Document toolboxDocument toolbox

Header

(v9.0) Web Elements and Locators

Web Elements and Their Properties

Web elements are crucial for understanding Test Automation. They are the controls or components used in the application. For instance, 'Password' is an element referred to as 'Label'. The input box underneath 'Password' is another element known as 'TextBox' or 'WebInput'. Similarly, you'll see other elements like 'radio button' and 'button' (Log in).

Note: The Internet Explorer WebElement Inspector doesn't support adding web elements for a Salesforce application.

Each type of web element has a distinct function and is classified into various categories based on this function.

The following are some commonly used web elements:

Web Elements Properties Generally, a property is a characteristic or attribute. For example, size is a property of your laptop. In the application being tested, a property is a mutable characteristic of a component that can be assigned different values.

Real-world examples of elements include a smartphone, a bicycle, a book, or a coffee cup. These elements share characteristics. A smartphone has properties like brand, model, color, and screen size. Similarly, software application elements also have properties. It's important to understand the properties of a web element and its role in test automation.

Commonly referred properties in functional test automation include:

  1. Name

  2. ID

  3. Class

Consider this example: 'Log in' is a web element of type button and it has the following properties with their respective values:

Name: Log in

Color: Green

Choosing the Right Properties

A web element may have multiple properties. Identifying a unique set of properties and their corresponding values is crucial for your test automation tool to recognize a specific web element uniquely each time during test automation.

For example, consider a web page with two identical input boxes. If your test automation needs to interact with only the first input box, you should choose a specific property that has a unique value, allowing your automation tool to pinpoint this specific web element.

In this case, the first input box has a value property = val1. You could use the value property here. However, this may not always be straightforward if the value properties change for some reason during subsequent rounds of testing.

Understanding Static and Dynamic Web Elements

Static Web Elements

A static web element is an element whose attribute values do not change. For instance, the attribute 'font-family' for a website's logo text typically remains constant. Identifying static web elements accurately is crucial for building reliable and maintainable test automation scripts. Misidentifying these elements can lead to ineffective or failed test executions.

Scenario: Imagine a login page where the username field's 'name' attribute is static, while its 'id' attribute is dynamically generated each time the page is loaded. Here, using the 'name' attribute would be the best practice for identifying this static web element since its value remains constant.

Dynamic Web Elements

A dynamic web element is one whose attribute values may change. For example, the value of the 'src' property of a carousel image on a homepage might vary. Identifying dynamic web elements correctly is critical for creating effective test automation scripts that can handle changes in the application.

Scenario: Let's consider a news website where the main headline's 'id' attribute changes based on the latest news story. In such cases, it would be better to identify the headline using a static attribute like 'class', or if there's a pattern in the dynamic attribute, we could use regular expressions. You can also parameterize the value to accommodate predictable dynamic changes.

Avoid attributes with unpredictable dynamism for identifying web elements, as this could lead to unreliable test scripts.

Setting Locator Priorities

The types of locators can be:

  1. Link

  2. Name

  3. ID

  4. XPath

  5. CSS

This sequence is adjustable according to your specific needs.

The locator priority settings help determine the best locator type for inspecting the HTML element. Adjusting these settings optimally can enhance the accuracy and efficiency of your test automation process.

Scenario: For example, if your application has consistently unique and static ID attributes, you might prefer setting 'ID' as the top priority locator. However, note that Qualitia does not utilize the 'ID' attribute when inspecting objects via XPath.

To modify the locator priorities, follow these steps:

  1. On the WebElement Inspector toolbar, click on the Settings icon to open the Locator Priority Settings window.

  2. Use the Up/Down buttons to adjust the priorities of the locator types.

  3. Click 'Restore Default' to revert to the original priorities.

  4. Click 'Cancel' to discard any changes.

  5. Click 'Ok' to apply the changes.

Setting the correct locator priorities will allow the WebElement Inspector to more effectively and efficiently identify the web elements during test automation.

Adjusting Locator Priority Settings

The locator types provided are:

  1. Link

  2. Name

  3. ID

  4. XPath

  5. CSS

This is the default order of priority, which can be customized to suit your specific needs.

Why It Matters: The sequence of locator types plays a pivotal role in how effectively and accurately Qualitia can identify web elements during automation testing. A proper locator priority sequence ensures a smooth, reliable, and efficient automation testing process, thereby reducing the possibility of errors or missed test cases.

How Qualitia Helps: Qualitia's built-in algorithm assists in identifying the most appropriate locator type when examining the web elements in your application. However, it's important to note that when inspecting objects using XPath, Qualitia does not utilize the ID attribute.

To modify the priority of locator types, you can follow these steps with Qualitia::

  1. On the WebElement Inspector toolbar, select the Settings icon. This action will open the Locator Priority Settings window.

  2. Use the Up/Down buttons to adjust the priorities of the locator types.

  3. If you wish to revert to the default priorities, click Restore Default.

  4. To discard any changes made, click Cancel.

  5. After making your desired changes, click Ok to apply them.

 By offering a flexible and customizable approach to setting locator priorities, Qualitia empowers you to tailor your automation testing process to best fit your application's unique characteristics. This adaptability ultimately contributes to creating more accurate and reliable automation tests, enhancing the overall efficiency and effectiveness of your testing efforts.

Footer