How was my WebElement found? By.Id / By.Name

64 views
Skip to first unread message

Oren Nahoom

unread,
Feb 8, 2016, 4:07:40 AM2/8/16
to Selenium Users


I have a WebElement passed on from external code, and i need to know how it was found.

was it found By.Id ? By.Xpath ? 

When debugging i noticed the WebElement has data stating how it was found, but i don't know how to extract it.

is it possible ?


Mundere Léandre

unread,
Feb 8, 2016, 11:44:34 AM2/8/16
to Selenium Users
Would you mind to share with us maybe a sample code that you are using? 

Doug Dragon

unread,
Feb 8, 2016, 1:19:20 PM2/8/16
to Selenium Users
The .ui-slider- tells me it's finding by class (elements starting with a . are class, # for id) but the circled overlay is clearly xpath.
That's about all I can gleam from the screenshot.

-Doug

David

unread,
Feb 9, 2016, 5:25:59 PM2/9/16
to Selenium Users
From the screenshot, it looks like the tooltip popup is likely with respect to the "slider" WebElement that is passed into the JS executor in the try block, not the highlighted line at the bottom regarding '.ui-slider-' which is obvious ByCssSelector or ByClassName. And that tooltip shows found by XPath.

And from what I can tell from the tooltip, it looks like the found by method is available in the object/class member "foundBy". However, based on my experience with Eclipse, which is what the screenshot appears to be for, foundBy is denoted as a red square, which I believe means is a private member, so it's likely not accessible to users. If it were though, then I would think one could extract it via slider.foundBy, although one might need further processing of the data as foundBy appears to be some object type itself, not a simple string.

And if it is private, perhaps one could modify/extend the applicable Selenium classes (and recompile as needed), to change foundBy to be public or protected.

David

unread,
Feb 9, 2016, 8:33:38 PM2/9/16
to Selenium Users
Adding on to my previous comment, I did a quick search and foundBy member is indeed private, but it's a simple formatted string. It looks like you can retrieve the foundBy info by simply calling toString() against the WebElement, e.g. slider.toString(), parent.toString(), based on:


However, I'm not sure what the result would be for WebElements found using JS executor (via invoking DOM methods or jQuery, etc.), I assume Selenium will map it to best match (XPath, CSS, ID, class, tag).

Would be interesting to follow up whether this is also exposed in the other language bindings by calling their toString method equivalents against a WebElement.
Reply all
Reply to author
Forward
0 new messages