getElementByXpath("//html[1]/body[1]/div[1]").click();
我正在寻找通过xpath自动点击的类似内容,但无法正常工作
You can use document.evaluate to find element by Xpath.(您可以使用document.evaluate通过Xpath查找元素。)
document.evaluate
click()
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>
1.4m articles
1.4m replys
5 comments
57.0k users