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
2 Answers 2
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.
Comments
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
Explore related questions
See similar questions with these tags.
$x("//button[text()='Download All']"), and make sure that only 1 element is returned. What happens when you useWebDriverWait? Do you get a timeout or some other error? Can you share the URL of the page? Something weird is going on.