[go: up one dir, main page]

0% found this document useful (0 votes)
19 views3 pages

Types of Xpath Memory Technique

Uploaded by

Kiran Ghandge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Types of Xpath Memory Technique

Uploaded by

Kiran Ghandge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Types of xpath :

1. xpath by attribute
Syntax :
//tagname[@attribute name = ‘attribute value’]
e.g. :- //input[@id = ‘abc’], //input[@id='autocomplete']
driver.findElement(By.xpath(“//input[@id = ‘abc’]”).click();
Tag Name and Attribute
Verse 1:
"Tag ka naam likho, syntax ka raaz samjho,
//tagname karo shuru, aur baaki steps samjho.
[@attribute name likho, condition lagaa ke,
='attribute value' karo match, element ko pakad ke."
Chorus:
"Tag aur attribute, dono ko yaad rakho,
Hinglish mein rhyme, isko easily yaad karo,
XPath ka rule hai simple, syntax ko samjho,
Coding mein life easy, is rhyme se karo!"

Key Breakdown:
1. //tagname - "Tag ka naam likho, syntax ka raaz samjho" (Start with the tag
name to identify the element).
2. [@attribute name='attribute value'] - "[@attribute name likho, condition lagaa
ke, ='attribute value' karo match" (Specify the attribute and its value to locate the
exact element).

2. xpath by text
Syntax :
//tagname[text() = ‘textvalue’]
e.g. :- //a[text() = ‘link1’]
//a[text()='linked text']
//a[contains(text(), 'partial text')]
Tag and Text Combo
Verse 1:
"Tag ka naam likho, phir text ka game chalu,
//tagname karo shuru, aur phir aage badho.
[text() likh ke, usko match karvao,
='textvalue' ke saath, element ko pakadvao."
Chorus:
"Tag aur text ka connection yaad rakho,
Hinglish mein rhyme, syntax ko yaad karo,
XPath mein yeh rule hai aasan,
Is rhyme se yaad rahe, sab kuch hai asaan!"

Key Breakdown:
1. //tagname - "Tag ka naam likho, phir text ka game chalu" (Start with the tag
name to identify the element).
2. [text()='textvalue'] - "[text() likh ke, usko match karvao, ='textvalue' ke saath"
(Use the text() function to match the exact text value).

3. xpath by contains()
a. Here we can mention the substring without writing a whole text, when
link/text is long in size.
b. If any non-breakable space (nbsp) is there.
We can use contains in two ways :
I. Contains with text() :
//tagname[contains(text(),’textvalue’)]
//h2[text()='Facebook helps you connect and share with the people in
your life.']→ normal text method
//h2[contains(text(),'Facebook ')]→using contains text
//a[contains(text(),‘link1’)]
Tag and Contains Magic
Verse 1:
"Tag ka naam likho, aur contains se milao,
//tagname karo start, syntax ko samjhao.
[contains(text(),’textvalue’)] karo apply,
Kisi bhi part se match, element ko try."
Chorus:
"Tag aur contains ka formula yaad rakho,
Hinglish mein rhyme, syntax ko yaad karo,
XPath ka yeh magic hai aasan,
Is rhyme se sab kuch hai asaan!"

Key Breakdown:
1. //tagname - "Tag ka naam likho, aur contains se milao" (Start with the tag name
to identify the element).
2. [contains(text(),’textvalue’)] - "[contains(text(),’textvalue’)] karo apply" (Use
contains to match a part of the text).

II. Contains with attribute :


//tagname[contains(@attribute name, ‘attribute value’)]
//input[contains(@name,‘first’)], //img[contains(@alt,'gle')]
Tag and Attribute Magic
Verse 1:
"Tag ka naam likho, attribute ko pakdo,
//tagname karo start, phir logic ko samjho.
[contains(@attribute name, ‘attribute value’)],
Kuch bhi match ho, yeh formula use karo."
Chorus:
"Tag aur attribute ka magic yaad rakho,
Hinglish mein rhyme, syntax ko yaad karo,
XPath mein yeh rule hai mast,
Is rhyme se yaad rahe, bina kisi fuss!"

Key Breakdown:
1. //tagname - "Tag ka naam likho, attribute ko pakdo" (Start with the tag name
and focus on the attribute).
2. [contains(@attribute name, ‘attribute value’)] - "[contains(@attribute name,
‘attribute value’)], kuch bhi match ho, yeh formula use karo" (Use contains to
match any part of the attribute value).

4. xpath by index
(//tagname[@attribute name = ‘attribute value’] )[2]
(//input[@type = ‘text’] )[2]
(//input[@name='radio'])[2]
(//h1[contains(text(),'Practice Page')])[1]
Tag and Second Element Magic

Verse 1:
"Tag ka naam lo, attribute ko pehchano,
//tagname se shuru, syntax ko samjho.
[@attribute name = ‘attribute value’], yeh laga trick,
Phir [2] se doosra element karo pick."

Chorus:
"Tag, attribute, aur number ka jadoo yaad rakho,
Hinglish mein rhyme, syntax ko yaad karo,
XPath mein yeh order hai bada cool,
Is rhyme se yaad rahe, rule ho yaad full!"

Key Breakdown:

1. //tagname - "Tag ka naam lo, attribute ko pehchano" (Start with the tag name and recognize
the attribute).

2. [@attribute name = ‘attribute value’] - "[@attribute name = ‘attribute value’], yeh laga
trick" (Apply the condition for the specific attribute).

3. [2] - "Phir [2] se doosra element karo pick" (Select the second element with this condition).

You might also like