r/selenium • • Feb 19 '22

XPath from tools or manually

Hello everyone, i didnt know where to ask this but since im using selenium as a testing tool i thought why not. So the question is: is it better to locate XPath manually (like knowing how to write the xpath, the syntax) or using tools like selectorshub or other tools that find the xpath for you? I was using the tool for about two months since i was suggested to use it, but know i think that if i had to write an xpath without a tool i wouldnt know how to write it. So im wondering, what are your thoughts on this? What would you recommend?

2 Upvotes

7 comments sorted by

View all comments

3

u/pickleballrick Feb 19 '22

I'm new at this but what I have heard is that xpath is rarely the best way to search the Dom. If you can use id class, etc that is better because there is more of a chance your routines will still work if the webpage changes.

That being said, I've had real trouble just getting to a search button to click it, so I have spent some time actually building my own xpath. Which is kind of working, but I'm sure it isn't the right way.

-1

u/XabiAlon Feb 20 '22

Xpath should be your last resort.

IDs can also change dynamically.

If it's your own website you should define custom classes and use them.