select search auto suggestions list using selenium

@Test
  public void GoogleAutoSearch() throws Exception{
  driver.get("http://www.google.com");
  Thread.sleep(1000);
  driver.findElement(By.id("lst-ib")).sendKeys("seleniumlearn");
  String str;
str=driver.findElement(By.xpath(".//*[@id='sbtc']/div[2]/div[2]/div[1]")).getText();
System.out.println(str);
String[] s=str.split("\n");
System.out.println(s.length);
for (int i = 0; i < s.length; i++) {
if(s[i].equalsIgnoreCase("seleniumlearn"))
{
System.out.println(s[i]);
driver.findElement(By.id("lst-ib")).clear();
driver.findElement(By.id("lst-ib")).sendKeys(s[i]);
driver.findElement(By.linkText("SeleniumLearn.com")).click();
}
}
  }

Tags: 

Comments