1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I tried browser.execute_script("arguments[0].click();", section_link) but this takes me to some other link! I wonder why ? Can you throw some light?
I actually figured out. There was a problem with the line section_link = td_list[1].find_element_by_xpath("//a"). When I changed the xpath to "a" instead of "//a", it worked fine. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.