Using Selenium to select a specific download button when there are many seemingly identical download buttons on the same page

36 Views Asked by At

I'm using an online educational platform that's generating daily excel spreadsheets. When I access my portal, I can click on a specific day or see a list of days, each with an inline download button. I'm new to Selenium in Python and I'm trying to download some or all of them from the list page. Here is a screenshot of an example list. The "Download Excel" button is in the drop-down at the end of each entry in the list Here is a screenshot of the Inspection of the download button

I haven't been able to find any css id, html, xpath etc. distinction to specify which of the download buttons I want to click. When I tried just specifiying the css selector, only the top item of the list was downloaded.

1

There are 1 best solutions below

0
zjalicf On

You can try to get all the buttons and click only the ones you want.

# Find all
download_buttons = driver.find_elements(By.XPATH, '//div[@class="download-button"]/button')

specific_button_index = 2 # the index of the button
download_buttons[specific_button_index].click()