0
votes

I have a dropdown who's inspection looks like this:

enter image description here

I want to check all the li elements and see if one of them contains the text "Other" for example...

So im writing in scala and I did this:

driver.findElement(By.className("dropdown-menu open")).click()
val myDropDown = driver.findElement(By.className("dropdown-menu open")).findElements(By.tagName("li"))
val answer = myDropDown.exists(a => a.getText == "Other")
println(answer.toString())

apparently its not true, what do you think I should do? thanks

2

2 Answers

0
votes

You have to find by By.cssSelector instead of By.className. By.className doesn't support compound css as you mentioned. So your code should be:

driver.findElement(By.cssSelector("dropdown-menu open")).click()
val myDropDown = driver.findElement(By.cssSelector("dropdown-menu open")).findElements(By.tagName("li"))
0
votes

If you want to check for all the li elements then u can try this :

driver.findElement(By.xpath("//div[@class='dropdown-menu open']")).click();
List<WebElement> liList =
driver.findElements(By.xpath("//div[@class='dropdown-menu open']//li[@class='nya-bs-option']"));
for(WebElement wb : liList)
{
   if(wb.getText().contains("Other"))
   {
     //...
   }
}