Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find XPath in Firefox Developer Edition?

Tags:

xpath

I have installed Firefox Developer Edition. How to find XPath in this browser? I would like to get XPath and use in Selenium script.

like image 277
Aravind Raja Avatar asked Aug 02 '18 06:08

Aravind Raja


People also ask

How can I get XPath in Firefox without Firebug?

Press F12, this opens the developer tools. Then click anywhere in the HTML structure and press Ctrl + F or Cmd + F if you're on a Mac. In the search bar that appears you can search by XPath, Css selectors or strings. So if you type //div/div/form for example, you can immediately check if the XPath works.

How do I get absolute XPath in Firefox?

Firefox browser (v72): Right-click webpage -> Inspect Element -> Right-click on web element -> Copy -> XPath (If the web element has any unique id then it will give you the relative XPath otherwise it will give absolute XPath).


2 Answers

Right-click on any element on the page. Select ‘Inspect Element’ in the pop-up menu. Right click on the tag in Inspector and select ‘Copy’ from pop-up & choose XPath. Paste the XPath wherever required.

like image 79
Anand S Avatar answered Oct 21 '22 06:10

Anand S


$x(path, [startNode])

$x(path) returns an array of DOM elements that match the given XPath expression.

For example, the following returns all the <p> elements on the page:

 $x("//p")

browser javascript console

The following example returns all the <p> elements that contain <a> elements:

$x("//p[a]")

browser javascript console

Similar to the other selector functions, $x(path) has an optional second parameter, startNode, that specifies an element or Node from which to search for elements.

browser javascript console

like image 42
oscrinfo Avatar answered Oct 21 '22 07:10

oscrinfo