views:

634

answers:

1

I want to define a custom locator with selenium, and I want it to use the existing xpath locator.

The code below does not work. How should I do it?

PageBot.prototype.locateElementByNg= function(text, inDocument) {
    var xpath = doSomeManipulation(text);
    return PageBot.prototype.locateElementByXpath(xpath, inDocument);
};
+1  A: 

Hi

Have a look at chrome://selenium-ide/content/locatorBuilders.js

Quick solution how you can build your own one based on xpath:attributes one:

LocatorBuilders.add('xpath:attributes', function(e) {

just change name to 'xpath:by_ng'

and use it as the only one in Preffered attributes const PREFERRED_ATTRIBUTES = ['by_ng'];

And then use it in

LocatorBuilders.order = ['xpath:by_ng','xpath:link'];

I will work for:

<a id="some" name="other" by_ng="this will be catched">test</a>

If you need it to work with structure like:

<a id="some" name="other" by_ng="this will be catched">
  <img />
  <span>Text</span>
  <p>Some text <b>bold</b></p>
</a>

then some additional changes will be needed.

Ula Karzelek