getElementByXpath("//html[1]/body[1]/div[1]").click();
I am looking for something like this for auto click by xpath but is not working
getElementByXpath("//html[1]/body[1]/div[1]").click();
I am looking for something like this for auto click by xpath but is not working
You can use document.evaluate
to find element by Xpath. After that, you can call click()
to click on it. Here's an example:
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
getElementByXpath('//button[@id="IDBodyPanelapp"]').click();
<button id="IDBodyPanelapp" onclick="alert('Button clicked!')">test</button>
More info here: https://stackoverflow.com/a/14284815/7919626