Is there a way to get the XPath in Google Chrome?

后端 未结 17 2022
暖寄归人
暖寄归人 2020-11-22 13:53

I have a webpage I want to use with YQL. But I need the XPath of a specific item. I can see it in the debug tools area for Google Chrome but I don\'t see a way to copy tha

相关标签:
17条回答
  • 2020-11-22 14:08

    xpathOnClick has what you are looking for: https://chrome.google.com/extensions/detail/ikbfbhbdjpjnalaooidkdbgjknhghhbo

    Read the comments though, it actually takes three clicks to get the xpath.

    0 讨论(0)
  • 2020-11-22 14:11

    For Chrome, for instance:

    1. Right-click "inspect" on the item you are trying to find the XPath.
    2. Right-click on the highlighted area on the HTML DOM.
    3. Go to Copy > select 'Copy XPath'.
    4. After the above step, you will get the absolute XPath of the element from DOM.
    5. You can make changes to make it relative XPath (because if the DOM changes, still your XPath would be able to find the element).

    a. To do so, by opening the 'Elements' panel of the browser, press CTRL+F, paste the XPath.

    b. Make changes as describes in the following example.

    Absolute xpath = //*[@id="app"]/div[1]/header/nav/div[2]/ul/li[2]/div/button

    Related xpath = //div//nav/div[2]/ul/li[2]/div/button

    When you make changes:

    1. make sure the XPath is unique within the DOM.
    2. still the web element is selected on the DOM and on the webpage.
    0 讨论(0)
  • 2020-11-22 14:15

    You can try using Chrome Web Extension TruePath which dynamically generates the relative XPath on right click on the web page and display all the XPath as menu items.

    0 讨论(0)
  • 2020-11-22 14:16

    No extension needed in chrome now. Right click on any element you want xpath for and click on "Inspect Element" and then again inside the Inspector, right click on element and click on "Copy Xpath".

    0 讨论(0)
  • 2020-11-22 14:18

    XPath Helper extension does what you need: https://chrome.google.com/webstore/detail/hgimnogjllphhhkhlmebbmlgjoejdpjl

    0 讨论(0)
  • 2020-11-22 14:19

    As of the latest update for chrome you can now click any element in the element inspector and copy the XPath to clipboard.

    0 讨论(0)
提交回复
热议问题