Selenium ElementNotInteractableException with ASP.NET report viewer (Python)

Viewed 144

I am trying to extract a CSV report from our company's ASP.NET ReportViewer via selenium. I have got as far as clicking the the export dropdown menu (see image), but I am unable to click the csv button (which will download the CSV report) I have tried waiting then clicking with no results.

My code:

driver = webdriver.Chrome(r'C:\Users\User\chromedriver.exe')  
url = 'Logon.aspx'  # target url

driver.get(url)  # open url

driver.find_element_by_xpath('//*[@id="ctl00_maincontent_txtUsername"]').send_keys('_user')  # username cred
driver.find_element_by_xpath('//*[@id="ctl00_maincontent_txtPassword"]').send_keys('_pswd')  # pass
driver.find_element_by_xpath('//*[@id="ctl00_maincontent_btnLogin"]').click()  # click login btn

driver.find_element_by_xpath('//*[@id="JobsReports"]').click()  # click job report btn
driver.find_element_by_xpath('//*[@id="ctl00_maincontent_TRCB3"]').click()  # click 'Task details' check box
driver.find_element_by_xpath('//*[@id="ctl00_maincontent_RunReportsBtn"]').click()   # click view report btn

time.sleep(3)

driver.switch_to.window(driver.window_handles[-1])
driver.implicitly_wait(120)

# driver.find_element_by_xpath('//*[@id="ReportViewer1_ctl05_ctl05_ctl00_ctl00"]/table/tbody/tr/td/input').click()
# driver.implicitly_wait(120)

driver.find_element_by_xpath('//*[@id="ReportViewer1_ctl05_ctl04_ctl00_ButtonLink"]').click()  # click save dropdown

driver.implicitly_wait(3)
driver.find_element_by_xpath('/html/body/form/div[3]/div/span/div/table/tbody/tr[3]/td/div/div/div[4]/table/tbody/tr/td/div[2]/div[2]/a').click()  # click 'CSV' to download

HTML / Layout:

HTML SNIPPET

<div style="border: 1px solid rgb(51, 102, 153); background-color: rgb(221, 238, 247); cursor: pointer;">
                                            <a title="CSV (comma delimited)" alt="CSV (comma delimited)" onclick="$find('ReportViewer1').exportReport('CSV');" href="javascript:void(0)" style="color: rgb(51, 102, 204); font-family: Verdana; font-size: 8pt; padding: 3px 8px 3px 32px; display: block; white-space: nowrap; text-decoration: none;">CSV (comma delimited)</a>
                                        </div>

Error:

  Traceback (most recent call last):
  File "C:\Users\User\PycharmProjects\Onsite_automation\main.py", line 32, in <module>
    driver.find_element_by_xpath('/html/body/form/div[3]/div/span/div/table/tbody/tr[3]/td/div/div/div[4]/table/tbody/tr/td/div[2]/div[2]/a').click()  # click 'view report' btn
  File "C:\Users\User\PycharmProjects\pythonProject3\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\User\PycharmProjects\pythonProject3\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\User\PycharmProjects\pythonProject3\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\User\PycharmProjects\pythonProject3\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=90.0.4430.72)

Thanks for your help!

2 Answers

Try

driver.find_element_by_xpath("//a[contains(@title, 'CSV (comma delimited)')]").click()

It should fix one locator problem. If you decided to use implicit wait, make it bigger (10). 3 seconds is too small value.

Thank you for helping me out with the locator @vitaliis, I changed:

driver.switch_to.window(driver.window_handles[-1])
driver.implicitly_wait(120)

To:

time.sleep(120)  # sleep to enable report to load
driver.switch_to.window(driver.window_handles[-1])  # Switch to report window

And it worked as desired.

Related