Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97813

How to click on javascript hyperlink element using selenium python

$
0
0

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?


Viewing all articles
Browse latest Browse all 97813

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>