At times, creating precise locator properties can be a bit challenging. But with proper knowledge and some tips a precise locator property can be created.

Here are a few tips to help you with the locators

  1. Make sure your locator property is unique.
  2. Sometimes there is a timing issue, which means that your web element/page is not yet loaded while the script was looking for it, hence add some wait time and re- test.
  3. A locator should be as small as possible
  4. Locator should not get effected by changes made to its parent or it’s own properties.

Reverse Lookup #

Let’s say that you want to click on a button and there is a similar button. Both buttons have id attributes, but they are dynamic and none of the attributes are unique in both the button elements.

In this case, you should first find the closest tag that is unique and then find the closest web element to the intended web element.

Dynamic element #

Please refer to the document on handling a Dynamic element, listed under related articles.

Verifying the locator property #

You can simply launch the scanner and verify the locator properties from there.
Or you can simply inspect the element and click on the Console tab, write the locator property there and press Enter key to verify it.

Format : $x(“xpath”)