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