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 badges31 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 501 раз.
Была ли эта статья полезной?
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
It might be just me but I can’t find any way to get DOM element’s XPATH in Firefox.
That was possible in Firebug, but now it’s deprecated in favor of Firefox Developer Tools, and the recommendation is not to use it any longer.
So, is there any way to get XPATH in Firefox and its Developer Tools?
asked Jan 6, 2017 at 3:53
Oleg MikheevOleg Mikheev
17.1k13 gold badges73 silver badges95 bronze badges
Open the developer tools in Firefox, then:
- Click on Console tab.
- Type
allow paste
if you are pasting anything. -
Type the XPath like so:
$x("path")
For example:
$x(".//*[@id='4th']/tbody/tr[1]/td")
Firebug also works well, so I suggest using that instead.
answered Jan 6, 2017 at 6:23
2
This feature is available in the Firefox DevTools since Firefox 56. To copy the Xpath of an element, right-click it within the Inspector and choose Copy > Xpath from the context menu.
In earlier versions of Firefox the option was placed in the first level of the context menu. As more copy options got added, they were moved into the Copy submenu.
answered Jan 6, 2017 at 9:59
Sebastian ZartnerSebastian Zartner
18.7k10 gold badges89 silver badges131 bronze badges
0
Even if there is no extension available for Firbug in Firfox V57/Quantum. Still we can performed same operation which we performed earlier with the help of firebug, in Firefox dev tool now. Firefox dev tool has more advanced function than normal browser. So It will be helpful for UIDesigner or any Developer.
Features in Developer Tool-Features in Developer Tool
To install & Download Firefox Developer Tool- Firefox Developer Tool
For XPath: Select any element by right click on it and choose Inspect Element(Q) then element/tag gets highlighted under inspector developer tool. Then Right Click on tag and select Copy=>Xpath or CssPath.
but the xpath or Css provided by above option will not be correct always if application is dynamic or having dynamic ids etc…
So better to use console option/ select console option (Press F12) write allow paste and enter.
For Xpath =>we have to use ($x) example: >>$x(“//p”) It will gives all p tag.
For Css path=> we have to use ($$) Example: >>$$(“p”) then Enter It will gives all p tag.
answered Nov 18, 2017 at 6:46
You can get the XPath in Quantum by right-clicking on the element html in Inspector and select Copy > XPath. For eg.
For instance the html below will give you the Xpath as – /html/body/form/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/table1/tbody/tr[4]/td1
answered Oct 3, 2018 at 16:45
user1554876user1554876
1931 silver badge18 bronze badges
You can also get an earlier version of firefox using from the release page.
Make sure you disable auto update otherwise your browser will upgrade to new one.
jopasserat
5,6914 gold badges31 silver badges49 bronze badges
answered Oct 7, 2017 at 7:21
jaibalajijaibalaji
3,0512 gold badges15 silver badges28 bronze badges
2
All the popular browsers provide an Html page web element inspector, you can easily check out the webpage structure use those built-in tools. Chrome, Firefox, Safari, Microsoft Edge all has it’s own built-in inspector. This article will tell you how to use all those web browser’s inspector and how to get an Html web element absolute / relative XPath value with the inspector.
1. How To Use Inspector To Get Absolute Or Relative XPath In Google Chrome, Firefox, Safari, Microsoft Edge.
1.1 Get Html Web Element XPath With Google Chrome Inspector.
- Right-click the web element in the web page opened in the google chrome web browser.
- Click the Inspect menu item in the popup menu list to open the inspector window.
- It will focus on the web element in the inspector window Elements tab.
- Right-click the focused web element in the inspector window.
- Click Copy —> Copy XPath menu item to copy the relative Xpath value, click Copy —> Copy full XPath menu item to copy the absolute Xpath value.
1.2 Get Html Web Element XPath With Firefox Inspector.
- Right-click the web element in the web page opened in the Firefox web browser.
- Click the Inspect menu item in the popup menu list to open the inspector window.
- It will focus on the web element in the popup window Inspector tab.
- Right-click the focused web element in the Inspector window.
- Click the Copy —> XPath menu item to get the absolute XPath value.
- If you want to get the relative XPath value in Firefox, you need to install some extensions such as TruePath.
- Click the Open Application Menu icon on the top right of the Firefox web browser.
- Click the Options menu item in the drop-down menu list.
- Click the Extensions & Themes menu item on the bottom left of the Options page.
- Input the keyword relative xpath in the Find more add-ons search box and click the Enter key to search.
- It will open a new window, and search out a list of XPath operator extensions, you can install the one you like to use it.
1.3 Get Html Web Element XPath With Microsoft Edge Inspector.
- Microsoft Edge provides the same function to Google Chrome.
- The steps and menu items name is the same.
- The menu items are all Copy —> Copy XPath, Copy —> Copy full XPath.