I would like Selenium driver to click on the export button as shown in the image.
Here is the html code:
JavaScript
x
2
1
<a class="btn bx-noIcon-margin" rel="tooltip" title="" onclick="if (!this.getAttribute('disabled')) jq_load_dialog('/index.php/filter/export/f/KbInvoiceFilter/m/kb_invoice/a/list',{autoOpen:false, bgiframe:false, close:'function() { $(this).dialog('destroy'); }', maxHeight:2000, maxWidth:2024, modal:true, resizable:false, title:'Download as Excel file', width:400},'#jqDialog'); return false;" href="/index.php/filter/export/f/KbInvoiceFilter/m/kb_invoice/a/list" data-original-title="Export current list"><i class="glyphicons download_alt"></i> </a>
2
I tried:
from the suggestion here
driver.find_element(by=By.XPATH("//a[@href='/index.php/filter/export/f/KbInvoiceFilter/m/kb_invoice/a/list']")).click();
but it returns
str is not callable.
Then, I tried using CSS_SELECTOR based on docs here:
JavaScript
1
2
1
driver.find_element(By.CSS_SELECTOR, 'i.glyphicons download_alt').click()
2
it returns
NoSuchElementException
Advertisement
Answer
Try with below
JavaScript
1
2
1
driver.find_element(By.CSS_SELECTOR, 'i.glyphicons.download_alt').click()
2
OR Add the ExplicitWait
JavaScript
1
12
12
1
from selenium.webdriver.common.by
2
import By
3
from selenium.webdriver.support.ui
4
import WebDriverWait
5
from selenium.webdriver.support
6
import expected_conditions as EC
7
8
element = WebDriverWait(driver, 20).until(
9
EC.element_to_be_clickable((By.CSS_SELECTOR, "i.glyphicons.download_alt")))
10
11
element.click();
12