public class GoogleSearch_b {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "c:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://google.com");
driver.findElement(By.name("q")).sendKeys("selenium");
driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
for(int j=3;j<7;j++)
{
Thread.sleep(4000);
WebElement box=driver.findElement(By.xpath("//*[@id='rso']"));
List<WebElement> links= box.findElements(By.tagName("cite"));
System.out.println("No.of links in the page are : " +links.size());
for(int i=1;i<links.size();i++)
{
String linkname=links.get(i).getText();
System.out.println(linkname);
}
driver.findElement(By.xpath("//*[@id='nav']/tbody/tr/td['"+j+"']/a")).click();
}
/* Page 2 : //*[@id='nav']/tbody/tr/td[3]/a
* Page 3 : //*[@id='nav']/tbody/tr/td[4]/a
* Page 4 : //*[@id='nav']/tbody/tr/td[5]/a
* Page 5 : //*[@id='nav']/tbody/tr/td[6]/a
*/
[quote:10lx0utr]WebElement box=driver.findElement(By.xpath("//*[@id='rso']"));
List<WebElement> links= box.findElements(By.tagName("cite"));
System.out.println("No.of links in the page are : " +links.size());
[/quote:10lx0utr]
these xpaths are not working on second page and its giving me an error. please try to find better xpaths.