1. How to find the Name of the links in a Google Page?
package com.Selenium;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Test;
public class WebDriverTest
{
@Test
public void testCollection()
{
System.setProperty("webdriver.ie.driver", "C:\\Automation2013\\Ieserver\\IEDriverServer.exe");
InternetExplorerDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com/");
List<WebElement> anchorlist = driver.findElements(By.tagName("a"));
for(WebElement element : anchorlist){
System.out.println(element.getText());
}
}
}
package com.Selenium;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Test;
public class WebDriverTest
{
@Test
public void testCollection()
{
System.setProperty("webdriver.ie.driver", "C:\\Automation2013\\Ieserver\\IEDriverServer.exe");
InternetExplorerDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com/");
List<WebElement> anchorlist = driver.findElements(By.tagName("a"));
for(WebElement element : anchorlist){
System.out.println(element.getText());
}
}
}
2. How to find number of links in a Google page?
package com.Selenium;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Test;
public class WebDriverTest
{
@Test
public void testCollection()
{
System.setProperty("webdriver.ie.driver", "C:\\Automation Nov 2013\\Ieserver\\IEDriverServer.exe");
InternetExplorerDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com/");
// How to find the number of links in a web page
int anchorlist1 = driver.findElements(By.tagName("a")).size();
System.out.println(anchorlist1);
}
}
No comments:
Post a Comment