-1

I have an issue with navigating in the listbox made of UL list using Selenium 4.3 and Python 3. The problem is that I don't know how to switch value from default to any other and when I'm trying to use click method on those <li> elements I'm getting only errors.

The screen shot of the html code below:

enter image description here

First I was trying to open whole list by clicking on it and after that choosing the element by the second click. I was trying to access that by ID, like this:

driver.find_element(By.ID, "__list1").click()

But it was an error that the asked element doesn't exist.

Do you have any idea how to navigate to different element from this kind of dropdown list? I know how to deal with this problem if the HTML tag would be a <select>.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

As per the HTML:

snapshot

The element identified through (By.ID, "__list1") is a <ul> tag which are generally not clickable.


Solution

Just like the usecase within the discussion you need to locate a <div> or a <span> element, which being clicked expands the <li> elements within either a <ul> or <ol>.

Your effective code block will be:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "div_or_span_which_expands_li"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='sapUiSimpleFixFlexContent']/ul//li[text()='All Cases']"))).click()

Note: You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • As you adviced I change the click() on the element that expands the ul list and this works great. The element looks like with id "__pane1-defaultSetDDLB-label". But in case of your solution - i still can not click the element of the list. I don't know if the xpath should be longer (for example should it start with the body tag and goes to the
  • element)? This line does an error with tiemout with backtrace: Microsoft::Applications::Events::EventProperties::unpack [0x00007FF7B7F16312+24642
  • – CzadowyHuopak Jul 27 '22 at 09:47