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

444    Asked by BellaBlake in QA Testing , Asked on Jul 9, 2021

 I am looking for something like:

getElementByXpath(//html[1]/body[1]/div[1])[removed]

I need to get the innerHTML of elements using JS (to use that in Selenium WebDriver/Java, since WebDriver can't find it itself), but how?I could use ID attribute, but not all elements have ID attribute.


Answered by Carl Paige

You can use the document.evaluate to solve javascript get element by xpath: Evaluates an XPath expression string and returns a result of the specified type if possible.


Your Answer

Interviews

Parent Categories