Is there a way to get element by XPath using JavaScript in Selenium WebDriver?

后端 未结 10 1548
后悔当初
后悔当初 2020-11-22 10:53

I am looking for something like:

getElementByXpath(//html[1]/body[1]/div[1]).innerHTML

I need to get the innerHTML of elements using JS (to

10条回答
  •  野性不改
    2020-11-22 11:49

    You can use javascript's document.evaluate to run an XPath expression on the DOM. I think it's supported in one way or another in browsers back to IE 6.

    MDN: https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate

    IE supports selectNodes instead.

    MSDN: https://msdn.microsoft.com/en-us/library/ms754523(v=vs.85).aspx

提交回复
热议问题