How to Print Auto Suggestion List In Java Selenium Example Program?

How to Print Auto Suggestion List In Java Selenium Example Program?

package com.softwaretestingo.dropdown;
import java.time.Duration;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class HandleAutoSuggestion 
{
	public static void main(String[] args) throws InterruptedException 
	{
		//Handle Auto Suggestion List
		WebDriver driver=new ChromeDriver();
		driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
		driver.manage().window().maximize();
		driver.get("https://www.google.com");
		
		driver.findElement(By.xpath("(//textarea)[1]")).sendKeys("SoftwareTestingo");
		List<WebElement> values=driver.findElements(By.xpath("//*[@role='presentation' and @class='wM6W7d']"));
		for(WebElement value:values)
		{
			System.out.println(value.getText());
		}
		driver.quit();
	}
}

I love open-source technologies and am very passionate about software development. I like to share my knowledge with others, especially on technology that's why I have given all the examples as simple as possible to understand for beginners. All the code posted on my blog is developed, compiled, and tested in my development environment. If you find any mistakes or bugs, Please drop an email to softwaretestingo.com@gmail.com, or You can join me on Linkedin.

Leave a Comment