Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get back the webdriver.Locator out of an elementFinder

Given I have the elmFinder variable:

var elmFinder = element(by.css('.thing'));

What if i need to get back the webdriver.Locator, a.k.a locator strategy? i.e.

elmFinder.??? //=> by.css('.thing')

I'm looking after the function ??? if it exists.

UPDATE:

This feature has been merged and we can now do:

elmFinder.locator();
like image 376
Leo Gallucci Avatar asked Mar 20 '23 17:03

Leo Gallucci


2 Answers

UPDATE:

This feature has been merged and we can now do:

elmFinder.locator();

Old answer: You cannot. The element finder does not keep a reference to the locator:

https://github.com/angular/protractor/blob/master/lib/protractor.js#L103

like image 170
Andres D Avatar answered Apr 09 '23 16:04

Andres D


What I typically do is store the selector in it's own var, and then place that string into the selector, so I can use both interchangably:

var cssThingSelector = '.thing';
var elem = $(cssThingSelector);

Something like that.

Edit:

I will also add that you can nest findElement calls from selenium webelement objects.

So, if there is another item in the inner html of the .thing web element (say, a span tag), you could just nest another findElement call:

var spanElem = elem.$('span');

You can do this as much as you'd like.

like image 40
yurisich Avatar answered Apr 09 '23 15:04

yurisich