Skip to main content

Implicit JavaScript Locators

Since v2.19.0

You can use the gwen.web.implicit.js.locators setting to enable Gwen to implicitly convert all locator bindings to their JavaScript equivalents and force all elements to be located by executing a script on the page instead of looking them up using standard web driver locator mechanism. Enabling this is useful when dealing with web sites that dynamically render or change the visibility of elements on pages or manipulate the DOM.

Value values are:

  • false to disable (default)
  • true to enable

Dyncamicaly rendered elements are best located by JavaScript. Consider enabling this mechanism if your locators are intermittently failing with what appears to be random hit-and-miss behaviour.

How it works

Say you define a locator in Gwen to lookup a user name field by ID as follows:

  Given user name can be located by id "username"

Gwen will normally lookup this field using the "By.Id locator" mechanism of web driver. This is the default Gwen behaviour when the gwen.web.implicit.js.locators setting is false.

If you set the gwen.web.implicit.js.locators setting to true however, Gwen will internally create a JavaScript equivalent locator for the above (and all other locator bindings you have defined) and execute that script on the page to locate the element instead of performing the standard web driver lookup. In the case of the above example, it would run document.getElementById("username") on the web page.

All the standard locators (id, name, css selector, class name, tag name, xpath, etc..) will be implicity converted to their JavaScript equivalents when this setting is enabled. So you don't have to rewrite your existing locator binding definitions if you decide that you want to locate all elements with JavaScript. Any explicitly defined JavaScript bindings you may have will not be affected.