In Firefox 50.1, Firebug is no longer available so I have to use the inspector but I cannot find copy —> xpath option that was available in Firebug. How can I find the xpath of an element using the inspector?
Bugs
4,4919 gold badges32 silver badges41 bronze badges
asked Jan 25, 2017 at 17:13
1
Follow Bellow Steps:
Step 1 : Right click on page -> Select (Inspect Element)
Step 2 : Pick an element from the page
Step 3 : Right Click on highlighted html -> Copy -> Xpath
answered Nov 24, 2017 at 8:57
Nanhe KumarNanhe Kumar
15.3k5 gold badges78 silver badges70 bronze badges
1
In Firefox you can use the web developer tools console for xpath validation like this:
1.Open Web Developer tools.
2.Click on Console
3.Type $x(«path»)
This should let you validate that your path is valid.
answered Nov 1, 2018 at 12:19
New GuyNew Guy
3832 silver badges12 bronze badges
0
You can’t, firefox’s inspector does not have such feature. However it does offer css selector which can be converted to xpath with various other tools.
It should be noted however that these generated selectors (xpath or css) are not accurate or reliable and you should avoid using this feature for anything but rare edge cases.
answered Jan 25, 2017 at 18:41
GranitosaurusGranitosaurus
20.4k5 gold badges55 silver badges81 bronze badges
6
Unfortunately this doesn’t work properly. When I use the copy xpath, I got this instead of the usual one: //*[@id=»gwt-uid-105″]
Which is just useless 
There aren’t any extension currently which could solve this. Looks like the only way is to run an old version of FF. Can have an old 32 bit and a new 64 bit version.
answered Nov 30, 2017 at 8:53
Xpath Using Firefox Console: **
Answer referenced from **Xpath Using Firefox Console in selenium webdriver
Steps:
Press F12( common for all browsers), Now firefox open developer tool like below.
-
Naviagte to console tab
-
On the console editor we can verify our Xpath
- For verifying xpath we have to use our xpath in following format : $x(«xpath»)
answered Jan 7, 2018 at 11:48
1
This is an old question but I’m glad to say that since FF 75 it supports searching by XPath, look at documentation. Here is a link to their blog entry
answered Apr 9, 2020 at 19:25
1
I know that this doesn’t answer directly to the question but it helped me a lot, use Pale Moon:
- Open any web page in Pale Moon browser
- Right click on an element of the page
- Select: «Inspect Element with Developer Tools» (a window shows up with element highlighted)
- Right click highlighted element
- Select: «Copy XPath»
And there you have it. You will get a «full» xpath even if the element has an id.
answered Jun 19, 2018 at 14:49
JosipJosip
755 bronze badges
I would rather you study how to create xpath on your own to select the element you need. It’s very simple and very very helpful specially when creating reusable methods/functions.
Go and see the xpath tutorial at w3schools or wherever.
Focus on the relationships between elements.
Edit:
Once you know how to construct a good-looking xpath, you can now test it using the browser console as mentioned by @mosaad. Still, you need to learn how to construct the xpath first. BTW, the copy xpath function wasn’t available back in Jan ’17. That is why I suggested he learn how to construct xpath. Even now that it is available though, I still suggest you learn because the xpath you get from those usually suck.
answered Jan 26, 2017 at 0:04
becixbbecixb
3551 silver badge9 bronze badges
2
Загрузить PDF
Загрузить PDF
XPath-путь к элементам сайта можно найти в большинстве браузеров с помощью инструментов разработчика. Firebug для Firefox позволит скопировать XPath-путь непосредственно в буфер обмена. В большинстве других браузеров XPath-путь к элементу можно найти посредством инструментов разработчика, но его придется форматировать вручную.
-
1
Установите Firebug для Firefox. Firebug является веб-инспектором для Firefox.
- Нажмите кнопку меню Firefox (☰) и выберите «Дополнения».
- Нажмите «Получить дополнения» – «Посмотрите больше дополнений».
- Найдите расширение Firebug и нажмите «Добавить в Firefox».
- Подтвердите, что вы хотите установить Firebug, а затем перезапустите Firefox (по запросу).
-
2
Откройте нужный веб-сайт. Firebug можно использовать для поиска XPath-пути к любому элементу сайта.
-
3
Нажмите кнопку Firebug. Она находится в правом верхнем углу окна браузера. В нижней части окна Firefox откроется панель Firebug.
-
4
Нажмите кнопку инспектора элементов. Она находится в верхнем ряду кнопок на панели Firebug (справа от кнопки «Параметры Firebug»). Значок этой кнопки имеет вид прямоугольника с курсором.
-
5
Щелкните по нужному элементу веб-страницы. По мере перемещения курсора по веб-странице на панели Firebug будут выделяться различные элементы. Остановитесь на элементе, XPath-путь к которому нужно узнать.
-
6
Щелкните правой кнопкой мыши по выделенному коду на панели Firebug. Если щелкнуть по нужному элементу веб-страницы, на панели Firebug выделится соответствующий код. Щелкните правой кнопкой мыши по выделенному коду.
-
7
В меню выберите «Копировать XPath». XPath-путь скопируется в буфер обмена.
- Если в меню выбрать «Скопировать мини-XPath», будет скопирован только короткий XPath-путь.
-
8
Вставьте скопированный XPath-путь куда нужно. Скопированный путь можно вставить куда угодно; для этого щелкните правой кнопкой мыши и в меню выберите «Вставить».
Реклама
-
1
Откройте нужный веб-сайт. В Chrome не нужны никакие расширения, чтобы найти XPath-путь к любому элементу веб-сайта.
-
2
Нажмите F12, чтобы открыть веб-инспектор. Он отобразится в правой части окна.
-
3
Нажмите кнопку инспектора элементов. Она находится в верхнем левом углу панели веб-инспектора. Значок этой кнопки имеет вид прямоугольника с курсором.
-
4
Щелкните по нужному элементу веб-страницы. По мере перемещения курсора по веб-странице на панели веб-инспектора будут выделяться различные элементы.
-
5
На панели веб-инспектора щелкните правой кнопкой мыши по выделенному коду. Если щелкнуть по нужному элементу веб-страницы, на панели веб-инспектора выделится соответствующий код. Щелкните правой кнопкой мыши по выделенному коду.
-
6
В меню выберите «Копировать» – «Копировать XPath». XPath-путь выбранного элемента скопируется в буфер обмена.
- Обратите внимание, что будет скопирован короткий XPath-путь. Расширенный путь можно скопировать с помощью расширения Firebug для браузера Firefox.
-
7
Вставьте скопированный XPath-путь. Скопированный путь можно вставить как любую другую информацию; для этого щелкните правой кнопкой мыши и в меню выберите «Вставить».
Реклама
-
1
Откройте меню Safari и выберите «Настройки». Чтобы получить доступ к веб-инспектору, нужно активировать функцию «Разработка».
-
2
Перейдите на вкладку «Дополнительно». Откроются расширенные настройки Safari.
-
3
Отметьте опцию «Показать меню разработки в строке меню». В строке меню отобразится меню «Разработка».
-
4
Откройте нужный веб-сайт. Закройте настройки Safari и перейдите на нужный веб-сайт.
-
5
Откройте меню «Разработка» и выберите «Показать веб-инспектор». Панель веб-инспектора откроется в нижней части окна.
-
6
Нажмите «Запустить поиск элемента». Эта кнопка имеет значок в виде перекрестья и находится в верхнем ряду кнопок на панели веб-инспектора.
-
7
Щелкните по нужному элементу веб-сайта. Код элемента будет выделен на панели веб-инспектора.
-
8
В верхней части панели веб-инспектора обратите внимание на XPath-путь. Скопировать XPath-путь нельзя, но расширенный путь отобразится над кодом на панели веб-инспектора. Каждая вкладка является формулой пути.[1]
Реклама
-
1
Откройте нужный веб-сайт. В IE не нужны никакие расширения, чтобы найти XPath-путь к любому элементу веб-сайта. Сначала откройте нужный веб-сайт.
-
2
Нажмите F12, чтобы открыть инструменты разработчика. Панель инструментов разработчика отобразится в нижней части окна браузера.
-
3
Нажмите «Выбрать элемент». Эта кнопка находится в левом верхнем углу панели инструментов разработчика.
-
4
Щелкните по нужному элементу веб-страницы. Будут выделены элемент и его код (на панели инструментов разработчика).
-
5
В нижней части панели обратите внимание на XPath-путь. Каждая вкладка (отображаются в нижней части панели) является формулой пути к выбранному элементу. Скопировать XPath-путь нельзя (это можно сделать с помощью расширения Firebug для браузера Firefox).
Реклама
Об этой статье
Эту страницу просматривали 17 511 раз.
Была ли эта статья полезной?
Is it possible to get the XPath of an element with the Firefox «inspect element» function (Q)?
The Chrome inspector can do this, but if I use the «Copy Unique Selector» option with Firefox’s inspector, I get a selector in a different format, not XPath.
I know there are extensions, but is it possible without extensions?
asked Feb 25, 2014 at 1:32
It is possible, but I doubt if anyone would try it more than a couple of times
Copy the unique selector
Open Scratchpad
Switch environment to browser
Paste the following snippet
Cu.import("resource:///modules/sessionstore/XPathGenerator.jsm");
XPathGenerator.generate(content.document.querySelector("unique selector placeholder"));
Paste the unique selector then form the Execute menu select Display
answered Feb 26, 2014 at 13:35
paapaa
7425 silver badges8 bronze badges
I know this question is old, but this feature now exists in the Developer tools of Firefox Quantum.
After inspecting, you can right-click the tag and Copy->XPath:
answered May 14, 2018 at 22:39
NH.NH.
18212 bronze badges
You can use Firebug extension on Firefox to get xpath expression. Chrome Inspector or firebug do not generate more accurate xpath which are based on attributes like Class, ID or related attributes, example below
//div[@class="address"]
//span[@id='phone']
So in that cause you can use some kind of xpath expression generator tools like http://webdata-scraping.com/xpath-generator/
Which has point and click user interface to generate different types of Xpaths.
answered Jul 13, 2016 at 14:26
1
Hello Folks,
In my last posts, we have learnt well how to locate web element in Selenium Webdriver using locators. We will learn in this post:
- Tools to find XPath/Css path in Firefox.
It is good practice to write XPath by yourself. Advantages of writing XPath by yourself:
- More perfect XPath expressions.
- Better understanding of HTML elements code.
- Clear concepts which helps in technical interviews
But, writing yourself will take time and it is tricky as well because you need to try different ways of writing expressions. I will suggest if you have time write it yourself otherwise use tools which I am going to discuss now.
Tools generate XPath of elements automatically. Just you need to copy it and use it.
Tools for Firefox:
Perform some steps:
- Open Firefox.
- Open Facebook URL.
- Right click on ‘Email or Phone’ text box and select ‘Inspect Element(Q)’ and observe.
Firebug:
Firebug is a add-on of Firefox which helps you in identifying HTML, CSS and JAVASCRIPT web elements more easily.
Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.
How to install Firebug:
- Launch Firefox browser.
- Type about:addons in address and hit ‘Enter’.
- Click on ‘Extensions’ from left side.
- Type ‘Firebug’ in search box and press ‘Enter’.
- Click on ‘Install’. It will download. It does not require restart of Firefox.
- You should see an icon of ‘bug’ in right side top corner.
For Firefox version < 51.0.1 and Firebug version < 2.0.18
- Now open Facebook URL and do Right click on ‘Email or Phone’ text box and select ‘Inspect Element(Q) with Firebug’ and observe. You will see below screen:
You can see separate tabs for HTML, CSS and Script(JS).
For Firefox version > 51.0.1 and Firebug version > 2.0.18
The Firebug extension isn’t being developed or maintained any longer. So, it will be disabled by default. When you do right click and see you will not get option to inspect with firebug. Firefox DevTools is alternative of Firebug.
Still you can use it but you need to enable it.
Steps to enable Firebug in Firefox:
1. Launch Firefox browser.
2. Type “about:config” is address bar and click on ‘I accept the risk’.
3. Search for :
a. ‘browser.tabs.remote.autostart’ and set the value to ‘false’
b. ‘browser.tabs.remote.autostart.1’ (if present) and set the value to ‘false’
c. ‘browser.tabs.remote.autostart .2’ and set the value to ‘false’
4. Restart the Firefox.
Now open Facebook URL and do right click on ‘Email or Phone’ text box. This time you will see ‘click on ‘Inspect Element(Q) with Firebug’.
Now question is what is use of installing firebug for us?
We can get XPath and CSS selector of Web element using Firebug. Let’s see how.
Do right click on web element which you want to locate and select Inspect Element with Firebug. It will highlight the code. Now do right click on highlighted code and observe options.
You will see three options:
- Copy XPath: It will copy absolute XPath in clipboard. (/html/body/div[1]/div[1]/div/div/div/div/div[2]/form/table/tbody/tr[2]/td[1]/input)
- Copy Minimal XPath: It will copy relative XPath in clipboard. (//*[@id=”email”])
- Copy CSS Path: It will copy CSSpath in clipboard. (html#facebook.tinyViewport.tinyHeight body.fbIndex.UIPage_LoggedOut._-kb.b_c3pyn-ahh.gecko.win.x1.Locale_en_GB div._li div#pagelet_bluebar div#blueBarDOMInspector div._53jh div.loggedout_menubar_container div.clearfix.loggedout_menubar div.menu_login_container.rfloat._ohf form#login_form table tbody tr td input#email.inputtext)
Note: Copying XPath from here, attribute values will be in double quotes. So, to use it in JAVA, replace double quote from single quote or escape it as:
Way 1:
//*[@id=”email”] should be changed as //*[@id=’email’]
Way 2:
//*[@id=”email”] should be changed as //*[@id=”email”]
You can verify copied XPath by hitting in console tab as below:
$x(“copied XPath”)
It will highlight element if correctly located.
We can achieve more functionality with Firebug with another add on named FirePath.
FirePath:
FirePath is a Firebug extension that adds a development tool to edit, inspect and generate XPath 1.0 expressions, CSS 3 selectors and JQuery selectors.
Advantages of using FirePath:
- Edit XPath expressions, CSS3 selectors and JQuery selectors.
- Evaluate the expression/selector on any HTML or XML documents.
- Display the result of evaluations in a Firebug-like DOM tree.
- Highlight the results directly on the document displayed by Firefox (works only with HTML documents).
- Generate an XPath expression or a CSS selector for an element by right clicking on it and selecting “Inspect in FirePath” in the context menu.
- Define the evaluation context (parent) of an expression/selector.
- Choose the document in which to evaluate the expression/selector (only applicable for HTML documents with frames or iframes). (If do not understand this point, do not take load. I will explain it in upcoming posts)
Installation of FirePath:
- Launch Firefox browser.
- Type about:addons in address and hit ‘Enter’.
- Click on ‘Extensions’ from left side.
- Type ‘FirePath’ in search box and press ‘Enter’.
- Click on ‘Install’. It will download. It requires restart of Firefox.
- Now open Facebook URL and do Right click on ‘Email or Phone’ text box and select ‘Inspect in FirePath’.
Points to be known from above screenshot:
- You will see a FirePath tab.
- It will highlight the web element under FirePath tab.
- It will give you relative XPath.
- It will give you document in which element is present. It will show iframe if element is present inside iframe. (Will discuss later).
- It will give you number of matching elements with given xpath.
- You can see highlighted ‘Highlight’ option. If you click it it will be not remain highlighted and will be not highlight matching web element in web page.
- Click on down arrow just beside XPath. You will see option to select css. You can find css path as well using FirePath.
- Now you can write XPath/css expression and click enter to know matching elements number. No need to go to console and try.
That’s it. You would have not seen this much long post on a very easy topic. But I just tried to explain all Whys and Hows.
If you like my posts, please like, comment and share. Suggestions and feedback are always welcomed.
Thank You!!
#HappyLearning
Author: Amod Mahajan
How can I verify my XPath?
I am using Chrome Developers tool to inspect the elements and form my XPath. I verify it using the Chrome plugin XPath Checker, however it does not always give me the result. What is a better way to verify my XPath.
I have also tried using Firebug to inspect the bug and also using the FirePath to verify. But does Firepath also verify the XPath.
My last option would be to use the Selenium WebDriver to confirm my XPath.
Jens Erat
37.2k16 gold badges80 silver badges96 bronze badges
asked Mar 21, 2014 at 23:25
Chrome
This can be achieved by three different approaches (see my blog article here for more details):
- Search in
Elementspanel like below - Execute
$x()and$$()inConsolepanel, as shown in Lawrence’s answer - Third party extensions (not really necessary in most of the cases, could be an overkill)
Here is how you search XPath in Elements panel:
- Press F12 to open Chrome Developer Tool
- In «Elements» panel, press Ctrl+F
- In the search box, type in XPath or CSS Selector, if elements are found, they will be highlighted in yellow.
Firefox (since version 75)
Since FF 75 it’s possible to use raw xpath query without evaluation xpath expressions, see documentation for more info.
Firefox (prior version 75)
- Either select «Web Console» from the Web Developer submenu in the
Firefox Menu (or Tools menu if you display the menu bar or are on Mac OS X)
or press the Ctrl+Shift+K (Command+Option+K on OS X) keyboard shortcut. -
In the command line at the bottom use the following:
-
$(): Returns the first element that matches. Equivalent todocument.querySelector()or calls the$function in the page, if it exists. -
$$(): Returns an array of DOM nodes that match. This is like fordocument.querySelectorAll(), but returns an array instead of aNodeList. -
$x(): Evaluates an XPath expression and returns an array of matching nodes.
-
Firefox (prior version 49)
- Install Firebug
- Install Firepath
- Press F12 to open Firebug
- Switch to
FirePathpanel - In dropdown, select XPathor CSS
- Type in to locate
answered Mar 22, 2014 at 3:41
Yi ZengYi Zeng
31.7k13 gold badges97 silver badges125 bronze badges
7
You can open the DevTools in Chrome with CTRL+I on Windows (or CMD+I Mac), and Firefox with F12, then select the Console tab), and check the XPath by typing $x("your_xpath_here").
This will return an array of matched values. If it is empty, you know there is no match on the page.
Firefox v66 (April 2019):
Chrome v69 (April 2019):
Adriano
3,7485 gold badges32 silver badges51 bronze badges
answered Mar 21, 2014 at 23:28
bosnjakbosnjak
8,2942 gold badges21 silver badges47 bronze badges
4
By using Chrome or Opera
without any plugins, without writing any single XPath syntax character
- right click the required element, then «inspect»
- right click on highlighted element tag, choose Copy → Copy XPath.

answered Jan 16, 2017 at 22:48
Eng. Samer TEng. Samer T
6,4556 gold badges36 silver badges43 bronze badges
3
Here’s a method I use to quickly visualize XPATH results within a HTML webpage — which as of HTML5 is technically an XML document (see note).
-
Open DevTools (F12)
-
Go to Console and type the following:
$x("//p[a]").forEach(myFancyResult => myFancyResult.style.backgroundColor = 'yellow');
//p[a] is an XPath expression that selects all <p> elements that contain <a> elements. The result is an array which is fed into the forEach method, from which we modify the elements backgroundColor.
Note:
The method is problematic against an XML document opened locally because the browser will apply a default style sheet to view the XML document with pretty colors and give you the ability to collapse and expand the document; This effectively wraps the XML document in div or span tags which messes up the original XML document, making this technique somewhat useless.
answered Feb 2 at 12:46
Another option to check your xpath is to use selenium IDE.
- Install Firefox Selenium IDE
- Open your application in FireFox and open IDE
- In IDE, on a new line, paste your xpath to the target and click
Find. The corresponding element would be highlighted in your
application
answered Jun 20, 2016 at 20:15
AJCAJC
96110 silver badges17 bronze badges















