I am trying to download a file from a website but am not able to interact with the download button.
The button is linked to the <a> tag with a href=#.
<div >
<a href="#" onclick="creditingRates.download();" style="display: block;">Download CSV</a>
</div>
I have tried the following but non seemed to work.
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//a[@href='#')]"))).click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@class='btn btn-download']/a[text()='Download CSV']))).click()
CodePudding user response:
- If you want to click the element you need to wait for element clickability, not just presence.
- From the shared HTML I see it's the
aelement who has, not a parentdivelement.
I can't debug this, only to guess, so I'd try the following:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='btn btn-download'][text()='Download CSV']"))).click()
Or maybe
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='btn btn-download'][contains(,text(),'Download CSV')]"))).click()
