my goal is to use selenium python to click on this hyperlink element , here are the 3 solutions I have tried, none of them worked.
<div class="navigation_item">
<a href="javascript:;" onclick="navigationMenu('students');">Students (165)</a>
</div>
Solution 1:
driver.find_element_by_link_text('Students (165)').click()
error message: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Students (165)"}
Solution 2:
driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[3]/div/div[1]/div[3]/div[7]/a').click()
error message: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[2]/div[1]/div[3]/div/div[1]/div[3]/div[7]/a"}
Solution 3:use javascript code
javascript = "document.getElementsByClassName('navigation_item')[3].click();"
driver.execute_script(javascript)
error message:selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read property 'click' of undefined
So, what went wrong with each solution? How can I make it work?