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 AutoSuggestiveDropdown {
public static void main (String[] args) throws Exception {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Users\\HP\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://rahulshettyacademy.com/dropdownsPractise/");
driver.findElement(By.id("autosuggest")).sendKeys("ind");
Thread.sleep(3000L);
List<WebElement> options = driver.findElement(By.cssSelector("li[class='ui-menu-item'] a")); //Error
for(WebElement option : options) {
if(option.getText().equalsIgnoreCase("India")) {
option.click();
break;
}
}
}
}
CodePudding user response:
You used 'findElement
' in 'driver.findElement(By.cssSelector("li[class='ui-menu-item'] a"))
'
You have to use 'findElements
' in 'driver.findElements(By.cssSelector("li[class='ui-menu-item'] a"));
'