Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Get element locator from WebElement #1829

Open
skyhirider opened this issue Jul 12, 2024 · 0 comments
Open

Feature: Get element locator from WebElement #1829

skyhirider opened this issue Jul 12, 2024 · 0 comments

Comments

@skyhirider
Copy link

Feature and motivation

Each WebElement must have a By locator that uniquely locates it.
As far as I can tell, the locator is protected and not available.
There are cases when pulling it out and re-using it would be helpful.
I propose exposing a getter for the By locator.

Usage example

You initialize a web element and it eventually becomes stale.
To refresh it, you either need to

  • remember the locator and re-load it by calling the locator. Not always possible if you pass the element around
  • use the @findby annotation so it auto refresh when stale. Can't use that if locators need to have variables.

If I need to check if an element exists

  • I used @findby, can't do that as it will patiently wait until it times out. Need to do a driver.findElementsBy(locator..).size()>0 , but can't as I can't reach the By to do this. So I copy paste my locator, once in annotation and once as a By in my fields, effectively duplicating code
  • if I do the same thing with a webelemennt I previous located, I can at least catch a stale exception and handle that, but would be nicer if I could get the by and fire up findelements to check if it still exists.

What if, instead, we could get the locator from each element. Would help with duplicating locators, as well as constructing new webelements or running the locators against the page again.

Opening after being told on the Selenium issues I should open one for the driver specification instead
SeleniumHQ/selenium#13660

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants