I need to click on specified li element using dropdown list: All subject areas on website. The problem is: cannot click on specified li element using Selenium.
For example, if I'm writting like:
 String textInput = "Agricultural and Biological Sciences";  
 //...
 // open the dropdown so the options are visible
 driver.findElement(By.className("dropdown"));
 // Get all of the options of dropdown list
 WebElement ulElement  = driver.findElement(By.cssSelector("ul.dropdown-options.dropdown-element"));
 List<WebElement> opts = ulElement.findElements(By.xpath(".//li/a"));
And trying to choose specified li element:
// Loop through the options and select the one that matches
        for (WebElement opt : opts) {
            if(opt.getText().equals(textInput)){
               opt.click();
               //...
            }
        }
The condition is simply skipped by the program.
If I changed to variant like:
  // Loop through the options and select the one that matches
        for (WebElement opt : opts) {
            if(!opt.findElements(By.xpath("//*[contains(text(), '" + textInput + "')]")).isEmpty()) {
                opt.click();
                //...
            }
        }
The condition isn't ignored and successfully passes, but then the program doesn't click on the button, and the list is closed.
Can someone suggest me how to solve the problem here?
