GUI Automation Framework Documentation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

GUI Framework Documentation

Author: Gonzalo Ivan Alarcon Roldan

© 2024 Evolution Virtual. All Rights Reserved.


XPATH Locators........................................................................................................................... 3
Locate elements by Attribute:.............................................................................................. 3
Locate nested elements by Attribute:..................................................................................... 3
Locate elements by Text:......................................................................................................... 3
Locate elements that contain part of a text in Attribute:...........................................................3
Locate elements that starts-with part of a text in Attribute:......................................................4
Locate elements by Attribute using AND & OR....................................................................... 4
Locate elements using following::............................................................................................4
Locate elements using ancestor::............................................................................................ 4
Locate elements using child::.................................................................................................. 5
Locate elements using preceding::.......................................................................................... 5
Locate elements using following-sibling::................................................................................ 5
Locate elements using parent::................................................................................................5
XPATH Locators

Locate elements by Attribute:


To target a web element by the Attribute, it is necessary to use the following format:

//tagname[@Attribute = 'Value']
//div[@class = 'class-name']

Locate nested elements by Attribute:


To target a web element that is into another web element we can use nested locators using the
following format:

//tagname[@Attribute = 'Value']////tagname[@Attribute = 'Value']


//div[@class = 'class-name']//button[@name = 'button-name']

Locate elements by Text:


To target a web element that has a text between tags <>text</> we can use the following locator
format:
//tagname[text() = 'Value']
//h3[text() = 'Text to locate']

Locate elements that contain part of a text in Attribute:


Sometimes the Attribute values are too large so we can target a web element using the
contains() function to write only a part of the Attribute value, we can use the following format:

Using Attribute:
//tagname[contains(@Attribute, 'Value')]
//div[contains(@class, 'part-of-the-class-value')]

Using Text:
//tagname[contains(text(), 'Value')]
//div//p[contains(text(), 'Part of the text')]
Locate elements that starts-with part of a text in Attribute:
Sometimes the Attribute values are too large so we can target a web element using the
starts-with() function to write only the first part of the Attribute value, we can use the following
format:

Using Attribute:
//tagname[starts-with(@Attribute, 'Value')]
//div[starts-with(@class, 'first-part-of-the-value')]

Using Text:
//tagname[contains(text(), 'Value')]
//div//p[contains(text(), 'First part of the text')]

Locate elements by Attribute using AND & OR


When using locators there could be some elements that have the same attributes or values, to
solve that we can use logical operators to make a deep target search, we can use the following
format:
//tagname[@Attribute = 'Value' or @Attribute = 'Value']
//button[@id = 'submit' or @name = 'btnName']
//button[@id = 'submit' and @name = 'btnName']

Locate elements using following::


To target all elements that are next to web elements that have a specific tagname, we can use
the following format:

//tagname[@Attribute = 'Value']//following::tagname
//div[@class = 'class-name']//following::input

Locate elements using ancestor::


To target all the web elements ancestors that have an specific tagname, we can use the
following format:

//tagname[@Attribute = 'Value']//ancestor::tagname
//input[@class = 'class-name']//ancestor::div
Locate elements using child::
To target all the child (son) web elements from a element with a specific tagname, we can use
the following format:

//tagname[@Attribute = 'Value']//child::tagname
//div[@class = 'class-name']//child::label

Locate elements using preceding::


To target all the elements that are before an element that have a specific tagname, we can use
the following format:

//tagname[@Attribute = 'Value']//preceding::tagname
//div[@class = 'class-name']//preceding::input

Locate elements using following-sibling::


To target all elements that are next to another element in the same hierarchic level that have a
specific tagname, we can use the following format:

//tagname[@Attribute = 'Value']//following-sibling::tagname
//div[@class = 'class-name']//following-sibling::input

Locate elements using parent::


To target the next parent tag that is above an specific element with a tagname, we can use the
following format:

//tagname[@Attribute = 'Value']//parent::tagname
//button[@class = 'class-name']//parent::div
//button[@class = 'class-name']//parent::div[1]

You might also like