PriyankaJ
PriyankaJ

Reputation: 390

Python Selenium : Unable to click on href

I am trying to click on a href link using Selenium Python. I am getting error ElementNotInteractableException. I am still able to get text attribute from that element , so I know its the right one. However, click doesn't seem to work.

<a href="/teacher_dashboard/sections/1725967" style="color: rgb(0, 173, 188); font-family: &quot;Gotham 5r&quot;, sans-serif; font-size: 14px; text-decoration: none;">Velaz /18-19/ 7A</a>
section_data = browser.find_element_by_xpath("//table")

tr_list = section_data.find_elements_by_xpath("tbody/tr")
print(len(tr_list))
for i in range(len(tr_list)):
    if i > 0: # ignore table header
        tr = tr_list[i]
        td_list = tr.find_elements_by_xpath("td")
        section_link = td_list[1].find_element_by_xpath("//a")
        if i ==16:
            print(len(td_list))
            print(td_list[1].text)
            print(section_link.text)
            section_link.click()

17
7
Velaz /18-19/ 7A

---------------------------------------------------------------------------
ElementNotInteractableException           Traceback (most recent call last)
<ipython-input-69-5baa70427952> in <module>
     12             print(td_list[1].text)
     13             print(section_link.text)
---> 14             section_link.click()

I also tried below code, but this throws some Javascript error :

webdriver.ActionChains(browser).move_to_element(section_link).click(section_link).perform()

Upvotes: 1

Views: 90

Answers (1)

officialrahulmandal
officialrahulmandal

Reputation: 3078

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

For Example:-

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

This is part of my code snippet will change the answer and update it with your code snippet in some time.

Happy coding :-)

Upvotes: 1

Related Questions