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

后端 未结 17 2042
暖寄归人
暖寄归人 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:19

    press Cntl + Shift + C
    select the element you wish to get its XPath by clicking on it
    right click on the highlighted part in the console
    copy -> copy XPath

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

    Use this extension, it generates xpaths based on id or class, which is probably what you want to use.

    Click on the browser icon, the panel is shown on the right corner of the page, then click start inspect, then click on any element to get your xpath.

    XPath Generator

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

    In Firebug in Firefox, you can right click on an element after inspecting it, and choose Copy XPath. I could not get ChromYQLip to work smoothly.

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

    All above answers are correct here is another way with screenshot too.

    From Chrome :

    1. Right click "inspect" on the item you are trying to find the xpath
    2. Right click on the highlighted area on the console.
    3. Go to Copy xpath

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

    I tried almost all the available extensions and found the below to be one of the best.

    ChroPath Extension link

    Just like FirePath, this extension directly gives you the Xpath when you click on Inspect.

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

    Google Chrome provides a built-in debugging tool called "Chrome DevTools" out of the box, which includes a handy feature that can evaluate or validate XPath/CSS selectors without any third party extensions.

    This can be done by two approaches:

    Use the search function inside Elements panel to evaluate XPath/CSS selectors and highlight matching nodes in the DOM. Execute tokens $x("some_xpath") or $$("css-selectors") in Console panel, which will both evaluate and validate.

    From Elements panel

    1. Press F12 to open up Chrome DevTools.

    2. Elements panel should be opened by default.

    3. Press Ctrl + F to enable DOM searching in the panel.

    4. Type in XPath or CSS selectors to evaluate.

    5. If there are matched elements, they will be highlighted in DOM. However, if there are matching strings inside DOM, they will be considered as valid results as well. For example, CSS selector header should match everything (inline CSS, scripts etc.) that contains the word header, instead of match only elements.

    From Console panel

    1. Press F12 to open up Chrome DevTools.

    2. Switch to Console panel.

    3. Type in XPath like $x(".//header") to evaluate and validate.

    4. Type in CSS selectors like $$("header") to evaluate and validate.

    5. Check results returned from console execution.

    If elements are matched, they will be returned in a list. Otherwise an empty list [ ] is shown.

    $x(".//article")
    [<article class="unit-article layout-post">…</article>]
    
    $x(".//not-a-tag")
    [ ]
    

    If the XPath or CSS selector is invalid, an exception will be shown in red text. For example:

    $x(".//header/")
    SyntaxError: Failed to execute 'evaluate' on 'Document': The string './/header/' is not a valid XPath expression.
    
    $$("header[id=]")
    SyntaxError: Failed to execute 'querySelectorAll' on 'Document': 'header[id=]' is not a valid selector.
    
    0 讨论(0)
提交回复
热议问题