How to click on the list of the <li> elements in an <ul> elements with selenium in python?

python, selenium

Solution

If you're able to open dropdown item but unable to click on item, you should try using `Explicit Waits` with `WebDriverWait` to wait until this element is visible and enable to click as below :-

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "ul#ulBirthYear a[data-value='2002']")))
element.click()

Or

element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "2002")))
element.click()

Problem

I tried to select 2002 in dropdown menu. It doesn't work at any late. I used xpath ``` driver.find_element_by_xpath("html/body/main/div/form/div[3]/div[1]/section/div[3]/fieldset/div[7]/dl[1]/dd/ul/li[1]/a").click() ``` but it doesn't work..I tried all the solutions I got... How can I select this?

Original source