Skip to content
Advertisement

Python and Selenium – Pick value from dropdown list

Trying to pick value in the dropwdown list as shown in picture – Dresses

Dropdown IMAGE with open HTML Dropdown IMAGE with open HTML

By this line i’m able to click and expand the dropdown

myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/main/div[2]/div/div/div[2]/section[3]/div/div[2]/div[1]/div'))).click()
myElem.click()

After i expand the dropdown list i tried to pick xPath/CSS selector for Dresses but nothing works

How i copy the Selector How i copy the Selector

Advertisement

Answer

Induce WebDriverWait() and element_to_be_clickable() and click on first dropdown div tag to expand and the click on the dropdown item.Hope this will work.

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.dropdown__selector"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//ul[contains(@class,'dropdown__menu')]//li[@class='dropdown__menu_item']//a[@data-et-on-tab='women' and text()='Dresses']"))).click()

Update

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.dropdown__selector"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[contains(@class,'dropdown__selector')]/following::div[1]//ul[contains(@class,'dropdown__menu')]//li[@class='dropdown__menu_item']//a[@data-et-on-tab='women' and text()='Dresses']"))).click()

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement