selenium: a custom locator that uses xpath locator


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


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>

Some text <b>bold</b>


then some additional changes will be needed.


  • Responsive design method for collapsing a div
  • unable to get jsonEncode in magento2
  • Cannot get text from text area
  • How to load gif image while ajax content is loading and javascript [duplicate]
  • converter json to two dimensional array
  • Getting error 'Cannot read property 'document' of undefined' while importing exp
  • Primefaces :radioButton inside a ui:repeat
  • Owin Authentication and claims in asp.net how to access user data
  • Update Google Maps traffic layer without page reloading
  • SQLite connection strategies
  • Remove changes from one element when event occurs on another element?
  • How to remove a SwiftyJSON element?
  • Convert Type Decimal to Hex (string) in .NET 3.5
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Allowing both email and username for authentication
  • jQuery .attr() and value
  • Email format validation in mvc3 view
  • Regex thinks I'm nesting, but I'm not
  • req.body is undefined - nodejs
  • How to get a value (ex: baseURL) in every Karate feature?
  • angularjs unit test when to use $rootScope.$new()
  • How to set/get protobuf's extension field in Go?
  • Submit form in a displaytag pagination
  • Validaiting emails with Net.Mail MailAddress
  • MySQL WHERE-condition in procedure ignored
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Web-crawler for facebook in python
  • How to delete a row from a dynamic generate table using jquery?
  • trying to dynamically update Highchart column chart but series undefined
  • using HTMLImports.whenReady not working in chrome
  • Authorize attributes not working in MVC 4
  • Bitwise OR returns boolean when one of operands is nil
  • EntityFramework adding new object to nested object collection
  • Is there any way to bind data to data.frame by some index?
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • java string with new operator and a literal
  • How to push additional view controllers onto NavigationController but keep the TabBar?