Reputation: 419
Here is the snippet of HTML I am drawing from:
<div class="exportlinks">
Export options:
<a href=[link]>
<span class="export CSV">CSV</span>
</a>
|
<a href=[really secret link here]>
<span class="export excel">Excel</span>
</a>
</div>
Here is the snippet of code that I am trying to use to do so:
exportToExcel = browser.find_element_by_link_text("Excel")
exportToExcel.click()
I had also tried to find the element by class name (export excel) to no avail.
Heck, I even tried to retrieve both links via find elements by class ("exportlinks") and then select from that list the one I wanted, but it returned an empty list.
Am I missing something here? Does it have to do with the fact that the text and class are in a ? Or the fact that this snippet of HTML is pretty deep in the rest of the HTML of the page?
Any help would be appreciated! Thanks!
Upvotes: 1
Views: 251
Reputation: 19164
if it dynamically generated you have to use WebDriverWait
exportToExcel = WebDriverWait(driver, 15).until(
lambda d: d.find_element_by_link_text("Excel")
# lambda d: d.find_element_by_css_selector('.export.excel')
)
exportToExcel.click()
Or if it in iframe
switch to it
iframe = driver.find_element_by_***("....")
driver.switch_to.frame(iframe)
exportToExcel = browser.find_element_by_link_text("Excel")
exportToExcel.click()
Upvotes: 1