Use Selenium Webdriver to capture all the values from Google Auto Suggest Edit Box



  • import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class AutoSuggestEditBox { public static void main(String[] args) { WebDriver driver=new FirefoxDriver(); driver.get("https://www.google.co.in/?gfe_rd=cr&ei=w3s7U6DQJsSJ8QfDloEg"); driver.findElement(By.id("gbqfq")).sendKeys("cognizant i"); List<WebElement> lst=driver.findElements(By.xpath("//td[@class='gssb_e']/table/tbody/tr")); for(int i=0;i<lst.size();i++){ System.out.println(lst.get(i).getText()); } } }



  • Try this: List<WebElement> lst=driver.findElements(By.cssSelector(".gssb_e > .gssb_m > tbody > tr")); for(int i=1;i<=lst.size();i++){ By selector = By.cssSelector(".gssb_e > .gssb_m > tbody > tr:nth-of-type(i) > td > div > table > tbody > tr > td:nth-of-type(1) > span"); WebElement el = driver.findElement(selector); System.out.println(el.getText()); } } I think this should work I haven't tried it. But that should print all auto suggests from google



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2