Click on dynamic dropdown element with selenium and python

I try to click on dropdown options using selenium and python. The problem is that the dropdown values are different each time I open the browser therefore, i can not use the HTML tags from the webpage.

I'm wondering if there's any way of clicking the values? I tried to use this line of code using answered provided by Sers in this case as an example How to select/click in a dropdown content using selenium chromewebdriver / python but I'm not sure how should I change/compose the class here.

att4 = WebDriverWait(driver, 2).until(ec.visibility_of_element_located((
                By.CLASS_NAME, f"div.awsui-select-option awsui-select-option-selectable[title='{l}']"))).click()

l is for each option in my dropdown, I need to click on each of them

enter image description here

1 answer

  • answered 2021-07-27 18:20 Prophet

    You are using a wrong, non-stable locator.
    Try this:

    att4 = WebDriverWait(driver, 2).until(ec.visibility_of_element_located((By.XPATH, "//div[@data-value='Bambino']"))).click()


    att4 = WebDriverWait(driver, 2).until(ec.visibility_of_element_located((By.XPATH, "//div[@title='Bambino']"))).click()

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum