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.

1
2
3
4
5
6
7
8
9
10
11
12
13

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.

1
2
3
4
5
6
7
8
9
10
11
12
13

Try Oyxlabs' Proxies & Scraper API

Residential Proxies

Self-Service

Human-like scraping without IP blocking

From

8

Datacenter Proxies

Self-Service

Fast and reliable proxies for cost-efficient scraping

From

1.2

Web scraper API

Self-Service

Public data delivery from a majority of websites

From

49

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
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

I'm interested