Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Print all the options displayed in Google auto suggestion box using Selenium

Category: Selenium WebDriver
        // Set Driver path
	System.setProperty("webdriver.chrome.driver", "C:\\drivers\chromedriver.exe");
	WebDriver driver=new ChromeDriver();

	//open google
	driver.get("https://www.google.com");
	driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

	//enter selenium in search box
	driver.findElement(By.name("q")).sendKeys("selenium ");

	//wait for suggestions
	WebDriverWait wait=new WebDriverWait(driver, 20);
	wait.until(ExpectedConditions.presenceOfElementLocated(By.className("sbtc")));

	WebElement list=driver.findElement(By.className("sbtc"));
	List rows=list.findElements(By.tagName("li"));

	for(WebElement elem:rows) {
	System.out.println(elem.getText());
	}

Leave a Reply

Your email address will not be published. Required fields are marked *