简体   繁体   中英

XPath for elements using Chrome?

Is there a way to get XPath of UI elements using Chrome Developer Tools (DevTools) ? I want to use the XPath in Selenium UI auto-testing.

How to get an XPath to an element in Chrome

  1. Right-click on the UI element and select "Inspect."
  2. A tree structure representation of the elements is shown.
  3. Right-click on any element and select "Copy > Copy XPath."
  4. Your clipboard will then have the XPath to the selected element. Paste it where you need it.

Realize that you may need to adjust manually to make more precise, more general, or more robust, depending upon the particulars of the element and what's on the rest of the page.

  1. Place the cursor on the element

  2. Perform right click and click on Inspect. You will see your elements getting highlighted

在此处输入图片说明

  1. On the highlighted element under the Elements Tab of the console, right click and Copy xpath like in the image below:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM