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

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

提交回复
热议问题