Endtest

Endtest

›Web Tests

Web Tests

  • How to create Web Tests
  • Finding elements in Web Applications
  • How to execute Web Tests
  • Assertions for Web Tests
  • IF Statements for Web Tests
  • Web Applications with restricted access
  • How to test in iframes
  • How to test in multiple tabs
  • How to test File Uploads
  • How to test File Downloads
  • How to test Emails
  • How to test PDF files
  • How to test Chrome Extensions
  • Dealing with reCAPTCHA
  • Dealing with Dynamic Locators
  • Dealing with Canvas Elements
  • Performing a Drag and Drop
  • Execute JavaScript
  • Testing WebRTC Applications
  • How to scroll in Web Tests
  • How to test Checkboxes
  • How to test Dropdowns
  • Dealing with Sessions
  • Web Crawler
  • Export Web Tests
  • Migrating from Selenium

Mobile Tests

  • How to create Mobile Tests
  • Finding elements in Mobile Applications
  • How to execute Mobile Tests
  • Assertions for Mobile Tests
  • IF Statements for Mobile Tests
  • How to scroll in Mobile Tests
  • Performing Complex Gestures

Advanced

  • Variables
  • Waits
  • Endtest API
  • Scheduler
  • Drive
  • Adding Collaborators
  • Computer Vision
  • Importing Test Cases
  • Using Loops
  • Data-driven Testing
  • Send API Requests
  • Read SMS
  • Execute SQL queries
  • Self-Healing Tests
  • Email Notifications
  • Slack Notifications
  • PagerDuty Notifications
  • Webhook Notifications
  • Automatic Backup
  • Advanced Settings
  • Multiple environments
  • How to stop a test
  • Utilities
  • Utilities API
  • Team
  • On-Premises

Integrations

  • Atlassian Jira
  • Slack
  • PagerDuty
  • Microsoft Teams
  • Mattermost
  • Jenkins
  • GitHub
  • Azure DevOps
  • GitLab
  • TeamCity
  • CircleCI
  • TravisCI
  • Bitbucket
  • Heroku
  • Bamboo Server
  • Test Case Management
  • SSO
  • BrowserStack
  • Sauce Labs

Dealing with Dynamic Locators

Introduction

Some frameworks will generate elements with dynamic locators, which will have a different ID with each rendering of the page.

For example, a button might have the ID register_325629 and might have the ID register_861951 after reloading the page.

Solutions

1. Change the Settings for the Endtest Chrome Extension

The Endtest Chrome Extension has a Settings section where you can configure it to not use the ID attribute.

endtest chrome extension settings

You can update those settings even after the recording has started.

If your elements have custom data attributes, you can take advantage of that and add the name of those attributes in the Custom data attributes textarea from the Settings section.

2. Write a custom XPath

The element might have a certain attribute that has a certain value that doesn't change over time.

You can write an XPath which locates the element by using that attribute, like this:

//*[@attribute = "attribute_value"]

You can also write an XPath which locates the element by using only part of the value of the attribute:

//*[contains(@attribute, "part_of_attribute_value")]

And you can also write an XPath which uses multiple attributes:

//*[@attribute_1 = "attribute_value_1" and @attribute_2 = "attribute_value_2" ]

3. Write a custom CSS Selector

The element might have a certain attribute that has a certain value that doesn't change over time.

You can write a CSS Selector which locates the element by using that attribute, like this:

[attribute='attribute_value']

But what if we actually need to find out what that ID is?

In order to tackle this situation, we have to use the Execute JavaScript action and locate the element by using one its attributes.

If the element has the title attribute with the value Register, we need to run the following JavaScript code with the Execute JavaScript action:

theId = document.querySelector("*[title='Register']").getAttribute("id");

After that, we can just transfer the value from that JavaScript variable to an Endtest variable with the Extract Value from JS Variable option from the Set Variable action.

More details about writing custom XPaths and CSS Selectors are available in the Finding elements in Web Applications chapter.

← Dealing with reCAPTCHADealing with Canvas Elements →
  • Introduction
  • Solutions
    • 1. Change the Settings for the Endtest Chrome Extension
    • 2. Write a custom XPath
    • 3. Write a custom CSS Selector
© Endtest Inc.