Skip to main content

Best practices

  • Use Chrome DevTools to copy the XPath directly by right-clicking the desired element and selecting "Copy" > "Copy XPath".

  • Install a reliable XPath Chrome extension like 'XPath Helper' or 'ChroPath' to simplify XPath extraction and ensure accuracy.

  • Manually construct and customize your XPath by analyzing the HTML structure and using specific attributes to create a more robust and less brittle XPath.

  • Always test your XPath in the Chrome console using $x('your-xpath-here') to verify it accurately selects the intended elements.

Scrollable code block. Use arrow keys to scroll.

Common issues

  • Ensure your XPath is not overly specific to avoid breakage when the webpage structure changes slightly.

  • Avoid using absolute XPaths as they are fragile; instead, opt for relative XPaths that are more resilient to changes in the page layout.

  • Use contains(), starts-with(), or ends-with() functions in your XPath to match elements dynamically based on partial attribute values.

  • Regularly update and review your XPaths to adapt to ongoing changes in the website's HTML structure.

Scrollable code block. Use arrow keys to scroll.

Try Oxylabs' Proxies & Web API

Residential Proxies

175M+ ethically sourced IPs for top-tier reliability

From

15

Datacenter Proxies

Fast cost-efficient infrastructure for any workload

From

15

Web API

One API for web discovery and data extraction

From

15

Useful resources

Using Google Sheets for Basic Web Scraping visuals
Guide to Using Google Sheets for Basic Web Scraping
vytenis kaubre avatar

Vytenis Kaubrė

2025-07-18

How to Find Elements With Selenium in Python
How to Find Elements With Selenium in Python
Enrika avatar

Enrika Pavlovskytė

2024-06-21

XPath vs CSS Selectors
Monika Maslauskaite avatar

Monika Maslauskaite

2021-07-13

Get the latest news from data gathering world

Scale up your business with Oxylabs