DEV Community

Discussion on: Selenium WebDriver and Dynamic Locators

Collapse
 
mstrelex profile image
Marat Strelets

Is this approach faster than searching with xpath? such as

//*[@state = 'active']

Collapse
 
philnash profile image
Phil Nash

I feel like the code in this post doesn't show an example of when you would need to use this technique, however it shows how to use it.

I can imagine a scenario where none of the Selenium selector strategies would apply (perhaps it moves about in the source of the page and shares attributes and classes with other items on the page) but you still need to pin down your element and get an ID for it. This would work in that case.

I'm pretty sure that using Selenium's native selection methods are what you would choose unless you simply can't get your element using them.