0

I am trying to click on an element that will download an Excel report. I am correctly locating the element using the below code. However, I am unable to click it by using .click or Select().

driver.find_element_by_xpath(element)

-.click returns "selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable"

-Select() returns "selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on elements, not on "

How do I click on the element? The element looks like this when I inspect it:

<a href="#" onclick="tablesToExcel(['summary','table1'], ['Report Profit'], 'myfile.xls')">
  <img src="/portalDispensary/vendors/tableExport/icon/xls.png" width="24px" class="mrx">
  "Export to Excel"
</a>
CEH
  • 5,701
  • 2
  • 16
  • 40
Syphon
  • 1
  • 1

2 Answers2

0

You can try to work around the ElementNotInteractable exception using a Javascript click:

element_to_click = driver.find_element_by_xpath("//a[text()='Export to Excel']")
driver.execute_script("arguments[0].click();", element_to_click)

The other alternative to to ensure the element is fully loaded before attempting to click by invoking WebDriverWait:

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


element_to_click = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, "//a[text()='Export to Excel']")))

driver.execute_script("arguments[0].click();", element_to_click)
CEH
  • 5,701
  • 2
  • 16
  • 40
0

Another solution using action class which will helpful to resolve ElementNotInteractable exception.

solution 1:

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

element = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, "//a[starts-with(.,Export to Excel')]")))
actionChains.move_to_element(element).click().perform()

solution 2:

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

element = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, "//a[@class='mrx']")))
actionChains.move_to_element(element).click().perform()
SeleniumUser
  • 4,065
  • 2
  • 7
  • 30