Articles on: Writing tests

Targeting Elements

1 - Matching by text

This matches by using either the text on screen, or aria labels. For example I.click("login") or I.fill("First Name","John")

One thing useful is that when there are multiple text of the same text, it is sometimes useful to do an I.see("Unique text") near the target text to interact with, think of it as instructing a user over the phone 😉


2 - Matching by HTML/CSS class name

Elements can be selected using HTML/CSS class name, with a dot prefix. For example I.click(".login-button")


3 - Matching by HTML/CSS ID

Elements can be selected using HTML/CSS ID, with a hash prefix. For example I.click("#close")


4 - Matching by XPath

Elements can be selected using XPath. For example I.click('//*[@id="tsf"]/div[2]/div[3]/center/input[1]')


Additional Note - Running actions inside an iframe

Finally when interacting with elements inside an iFrame, especially with salesforce, SAP, Shopify. You can improve the accuracy by running actions within a selected iframe context. For example:


UI.context("#unique-iframe-id", function() {
I.click("Button inside iframe")
//... other actions
})

Updated on: 19/09/2023

Was this article helpful?

Share your feedback

Cancel

Thank you!