Get back the webdriver.Locator out of an elementFi

2019-07-09 07:09发布

问题:

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();

回答1:

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



回答2:

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.