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

0 votes

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 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.

Nov 26, 2020 in Selenium by Rajiv
• 8,880 points
248 views

1 answer to this question.

0 votes

You can use the document.evaluate:

Evaluates an XPath expression string and returns a result of the specified type if possible.

answered Nov 26, 2020 by Gitika
• 65,850 points

Related Questions In Selenium

0 votes
2 answers

Is there any way to get the text of a web element using Selenium Webdriver?

use gettext() in java : string lableText = ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,010 points
5,053 views
0 votes
2 answers

What is the best way to handle a Javascript popup using Selenium Webdriver?

webDriver.switchTo().alert() it inbuild selenium only //Store the alert ...READ MORE

answered Sep 2, 2020 in Selenium by Sri
• 3,010 points
4,758 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
4,319 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,010 points
5,243 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
3,125 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2, 2020 in Selenium by Sri
• 3,010 points
3,621 views
+1 vote
4 answers

How to get typed text from a textbox by using Selenium Webdriver?

Hey Ashmita, to get the typed text ...READ MORE

answered Jun 24, 2019 in Selenium by Abha
• 28,000 points
14,907 views
0 votes
8 answers

How to open a link in new tab of chrome browser using Selenium WebDriver?

This below code works for me in ...READ MORE

answered Dec 13, 2020 in Selenium by Gitika
• 65,850 points
56,176 views