4

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();
Leo Gallucci
  • 16,355
  • 12
  • 77
  • 110

2 Answers2

5

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

Leo Gallucci
  • 16,355
  • 12
  • 77
  • 110
Andres D
  • 8,910
  • 2
  • 26
  • 31
  • Thanks for you answer, i submitted a pull request to add the reference, feel free to +1 there if you agree with the change: https://github.com/angular/protractor/pull/800 – Leo Gallucci May 12 '14 at 23:02
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.

yurisich
  • 6,991
  • 7
  • 42
  • 63
  • Thanks for you answer, i submitted a pull request to add the reference, feel free to +1 there if you agree with the change: https://github.com/angular/protractor/pull/800 – Leo Gallucci May 12 '14 at 23:02