QA_automation_1743853980
QA_automation_1743853980
(Automation QA/SDET)
Prepared by:-
Kushal Parikh
Checkout my Topmate : https://topmate.io/kushalparikh11/
//input[contains(@id, 'username')]
This will locate any `<input>` element where the `id` attribute contains
"username".
This function is helpful when an attribute starts with a known prefix but
changes dynamically.
//button[starts-with(@id, 'btn_')]
This will locate any `<button>` element whose `id` begins with "btn_".
For elements with static text values, `text()` can be used for direct
matching.
//button[text()='Submit']
This will locate any `<button>` element containing the exact text
"Submit".
//button[normalize-space()='Proceed']
//input[@type='submit' or @type='button']
This will select an `<input>` element where the `type` is either "submit"
or "button".
This will select an `<input>` element where the `type` is "text" and the
`name` is "username".
• Parent Selection
//span[text()='Username']/parent::label
• Child Selection
//div[@class='container']/child::ul
//label[text()='Password']/following-sibling::input
//input[@id='password']/preceding-sibling::label
• Ancestor Selection
//input[@id='search']/ancestor::form
• Descendant Selection
//div[@class='wrapper']/descendant::a
Finds all `<a>` elements nested within a `<div>` with class "wrapper".
Syntax:
//input[translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz')='username']
• Limitations
• By Tag Name
div
• By ID (``)
#login-button
• By Class (`.`)
.btn-primary
• By Attribute
input[type='text']
div > p
• Descendant (`space`)
div p
h2 + p
h2 ~ p
---
• Using `nth-child()`
ul li:nth-child(3)
• Using `nth-of-type()`
div:nth-of-type(2)
---
• Contains (`*`)
input[name*='user']
input[name^='first']
input[name$='name']