0

I'm trying to click a "Download All" button using Selenium in Python. Here's the relevant HTML from inspect:

<button title="" type="button" class="bds-button variant-primary" data-title="">Download All</button>

I've tried literally everything I can think of:

XPath:

driver.find_element(By.XPATH, "//button[text()='Download All']").click()

CSS Selector:

driver.find_element(By.CSS_SELECTOR, "button.bds-button.variant-primary").click()

Looping through all buttons:

buttons = driver.find_elements(By.TAG_NAME, "button")
for b in buttons:
    print(f'Text: "{b.text.strip()}" | Class: {b.get_attribute("class")}')
    if b.text.strip() == "Download All":
        b.click()

Explicit waits:

WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.XPATH, "//button[text()='Download All']"))
).click()

Scrolling into view:

driver.execute_script("arguments[0].scrollIntoView(true);", button)

Checking for iframes using:

print(driver.find_elements(By.TAG_NAME, "iframe"))

Checking for shadow DOMs, but I don’t see any shadow roots.

What I know:

  • The button is visible in the browser.

  • The button is not inside an iframe.

  • The button does not appear to be in a shadow DOM.

  • The page is fully loaded before interaction.

  • There's no id attribute on the button.

Here is a screenshot of the html elements: enter image description here

7
  • Have you tested that the XPath is unique on the page? Open the dev console, use $x("//button[text()='Download All']"), and make sure that only 1 element is returned. What happens when you use WebDriverWait? Do you get a timeout or some other error? Can you share the URL of the page? Something weird is going on. Commented May 28 at 21:00
  • Can you not find the element, or can you find it, but not click it? What exception are you getting? Commented May 29 at 0:08
  • Please post the full HTML of the page or provide the URL. We can't predict where the button is located on the page or how it behaves. Commented May 29 at 4:24
  • Can you share the URL for the page you're trying to work with? Commented May 29 at 6:18
  • Please add the error you get. Commented May 29 at 11:31

3 Answers 3

0

You have not provided the URL or the full HTML of the page. Tried to decipher the page from your screenshot. Have you made sure that the panels are open when you are trying to click the button? From the class name of the divs, it looks like you have to open some panels before you can see the button.

First, check if the element exists or not in the DOM from your code. Use the full CSS selector.

div#web-takeoff > div.web-takeoff__container > div.web-takeoff__page--panel-open > div.panel--open > div.panel__content--open > div.panel__documents > div.takeoff-control > button.bds-button.variant-primary``

If you see that the element exists. Then check if it is clickable or not.

If it exists, then it should be clickable using the script executor.

You have not provided the error. I'm assuming your selectors are not getting the button. So try again and see if you can get the button from your code.

Sign up to request clarification or add additional context in comments.

Comments

0

try this

wait = WebDriverWait(driver, 10) button = wait.until(EC.presence_of_element_located((By.XPATH, "//button[contains(., 'Download All')]")))

Or

 wait = WebDriverWait(driver, 10) button = wait.until(EC.element_to_be_clickable(
    (By.CSS_SELECTOR, "button.bds-button.variant-primary") ))


driver.execute_script("arguments[0].scrollIntoView(true);", button) driver.execute_script("arguments[0].click();", button)

buttons = driver.find_elements(By.CSS_SELECTOR, "button.bds-button.variant-primary")
    for btn in buttons:
        if btn.is_displayed():
            driver.execute_script("arguments[0].click();", btn)
            break

3 Comments

Unfortunately I tried that code and it still doesn't work. :( I added a screenshot of the html elements to the bottom of the post though, thanks!
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
Try alternative like - use CSS Selector by Class By.CSS_SELECTOR, "button.bds-button.variant-primary"
0

Try:

buttons = driver.find_elements_by_xpath("//*[contains(text(), 'Download All')]")

for btn in buttons:
    btn.click()

Inspired by Click button by text using Python and Selenium.

2 Comments

Unfortunately its not working :( I think it may have to do with the html or how the website is set up, but I'm not sure.
Is it not working because it cannot be identified, or is the issue that the click action is not functioning? What exactly is the problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.