0

I am trying to use selenium click to open dropdown menu and then click again to download a file. Common error I get is that the "element is not attached to the page document" Have tried different codes but here's one:

#button = driver.find_element_by_xpath('//ul[@class="dropdown-menu-right dropdown-menu"]')
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, "options-dropdown")))
element.click()

HTML snapshot:

enter image description here

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

1 Answers1

0

Generally <ul> nodes along with it's decendent <li> nodes gets expanded clicking on <span> nodes.


Solution

To click and open the i.e. to expand the <li> nodes you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.dropdown-toggle#options-dropdown"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='dropdown-toggle' and @id='options-dropdown']"))).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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352