Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from WebElement to List<WebElement>

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;

           }
           
           
       }
       
    
    }
}

>Solution :

You used ‘findElement‘ in ‘driver.findElement(By.cssSelector("li[class='ui-menu-item'] a"))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You have to use ‘findElements‘ in ‘driver.findElements(By.cssSelector("li[class='ui-menu-item'] a"));

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading