0

getElementByXpath("//html[1]/body[1]/div[1]").click();

I am looking for something like this for auto click by xpath but is not working

Word Rearranger
  • 1,306
  • 1
  • 16
  • 25
amino lok
  • 23
  • 5

1 Answers1

0

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

Word Rearranger
  • 1,306
  • 1
  • 16
  • 25