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.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++){


  • please guys help me to solve this program using webdriver in java language i dont find the exact solution to get all the autosuggest editbox list in a console
    – swati
    Commented May 18, 2014 at 23:22
  • What is the result from your code? It helps to have a bit more context than just the code.
    – Kate Paulk
    Commented May 19, 2014 at 11:10

2 Answers 2


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);


I think this should work I haven't tried it. But that should print all auto suggests from google

List<WebElement> suggestions=driver.findElements(By.cssSelector("ul>li.sbct"));
            for(int i=0;i<suggestions.size();i++)
                System.out.println(i+" "+suggestions.get(i).getText());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.