0

Do you know if it was possible to click with selenium on a non select dropdown list?

I need to interact with this site : https://ec.europa.eu/info/funding-tenders/opportunities/portal/screen/opportunities/projects-results

And click on the "Filter by programme" and after scraping return to the 1st page.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
rocheteau
  • 68
  • 6

2 Answers2

0

Drop Down Navigation

Elements within a dropdown list are typically hidden until the dropdown is initiated. Knowing this, the dropdown must be clicked on before clicking on any of the elements within the list. See below code for basic example:

from selenium import webdriver

driver = webdriver.Chrome()

dropdown_list = driver.find_element_by_xpath("XPATH_OF_DROPDOWN_LIST")
dropdown_list.click()

dropdown_element = driver.find_element_by_xpath("XPATH_OF_DROPDOWN_ELEMENT")
dropdown_element.click()

WebDriverWait

For a more advanced and better performing example, I would recommend the implementation of WebDriverWait as there sometimes is a lag between the elements of the dropdown list becoming available:

dropdown_element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "XPATH_OF_DROPDOWN_ELEMENT")))

Additional Resource

For those unfamiliar, the difference between time.sleep and WebDriverWait is that time.sleep will always wait N number of seconds where N is time.sleep(N). WebDriverWait however, will wait up to N seconds where N is WebDriverWait(driver, N). Meaning if WebDriverWait variable is set to 10 seconds, but the element becomes available in 2, the driver will perform the action in the 2 seconds and move onto the next command. But if the element takes longer than 10 seconds to show up, the program will throw a timeout exception.

Luke Hamilton
  • 637
  • 5
  • 19
0

The Filter by programme dropdown list opens up on clicking on the <label> element.


Solution

To click and expand the dropdown list you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using XPATH:

    driver.get("https://ec.europa.eu/info/funding-tenders/opportunities/portal/screen/opportunities/projects-results")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.wt-cck-btn-add"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[text()='Select a Programme...']"))).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
    
  • Browser Snapshot:

ec_europa_eu

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