Is there an elegant way to get the By locator of a Selenium WebElement, that I already found/identified?
To be clear about the question: I want the
Answer is No. You cannot extract a By
from a previously found WebElement by default.
That being said - it's possible to implement a custom solution, but Selenium does not offer this out-of-the-box.
Consider the following, on "why"..
By by = By.id("someId");
WebElement e = driver.findElement(by);
you already have the By
object, so you wouldn't need to call something like e.getBy()