pythonseleniumxpathwebdriverwebdriverwait

How can I choose an option in a list through selenium?


My code is:

WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH, "//option[@value='/icpplustieb/citar?p=8&locale=es']"))).click()

The URL is: https://icp.administracionelectronica.gob.es/icpplus/index.html

I would like to choose Barcelona as a Region.


Solution

  • Use selenium select() class

    select =Select(WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='form']"))))
    select.select_by_visible_text("Barcelona")
    

    You need to import the following library:

    from selenium.webdriver.support.ui import Select