Skip to content
Advertisement

clicking on hyperlink using xpath and css selector do not work

I would like Selenium driver to click on the export button as shown in the image. enter image description here

Here is the html code:

<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>

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:

driver.find_element(By.CSS_SELECTOR, 'i.glyphicons download_alt').click()

it returns

NoSuchElementException

Advertisement

Answer

Try with below

driver.find_element(By.CSS_SELECTOR, 'i.glyphicons.download_alt').click()

OR Add the ExplicitWait

from selenium.webdriver.common.by
import By
from selenium.webdriver.support.ui
import WebDriverWait
from selenium.webdriver.support
import expected_conditions as EC

element = WebDriverWait(driver, 20).until(
   EC.element_to_be_clickable((By.CSS_SELECTOR, "i.glyphicons.download_alt")))

element.click();
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement