Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mals14/2a6b691438eefdaba979eef9d4cbe95b to your computer and use it in GitHub Desktop.
Save mals14/2a6b691438eefdaba979eef9d4cbe95b to your computer and use it in GitHub Desktop.
Automating a javascript button click based on element's XPath
Title: Automating a javascript button click based on element's XPath
Source: https://stackoverflow.com/a/49084290/3973491
html:
<div>
<a href="#" onclick="alert('ok')">
<img src="">
</a>
</div>
javascript:
var xPathRes = document.evaluate ('//div[1]/a[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
xPathRes.singleNodeValue.click();
jsfiddle:
https://jsfiddle.net/7fm89aqd/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment