Hurry! 20% Off Ends SoonRegister Now

XPATH Usage in Selenium

XPATH Usage

There are times that you will need to find elements that are the same except for the difference in one or two attributes. To handle this, we can add the attributes to the query so that we can try to make the element more unique for use in the test. The format can be used for any attribute on any element.
It will always follow the xpath=//element [@attribute=’attribute value’].
For example, if you have two div elements on the page but they only differ by the class attribute, your XPath query would look like
xpath=//div[@class=’classname’]

For an in-depth understanding and practical experience, Explore Online Selenium Training.

Xpath usage:-

1)  Two object has same attributes

Xpath usage
2)  The object attribute changing dynamically–facebook
3) Element has no attributes.

Related Page: Finding Elements By XPATH And Using CSS - SELENIUM

MindMajix Youtube Channel
input
Syntax:-
//–parent element /child element
//element[@attribute=’attribute name’]
Example 1:-
example
//button[@id=’123′]

Example 2:-

SyntaxFace book code:-

Face book code

u129747_3
u131602_3

Checkout Selenium Interview Questions

Rightstart:-

href=”https://www.rightstart.com/search/result/?link_location=default.leftnav& 
ocat=707″ class=”current”>Travel Gear

Checkout Selenium Tutorial

Using attribute:-

//a[@href=’https://www.rightstart.com/search/result/?link_location=default.leftnav&ocat=707′]

Using Prent element:-

//dd[@class=’last odd’]/ol/li[3]/a

Example for Link:-

Link HTML
//a[@class=’current’] –its not working
//a[@href=’https://www.rightstart.com/search/result/?link_location=default.leftnav 
&ocat=707′]

Xpath using position:-

//element[@att=’attname’]/element1/element2 //dd[@class=’last odd’]/ol/li[10]/a

Explore Selenium Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!


Dynamic element:-

Dynamic element
//element[@att=’attname’]
//input[@type=’submit’ and @value=’Log In’]

 

Job Support Program

Online Work Support for your on-job roles.

jobservice

Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:

  • Pay Per Hour
  • Pay Per Week
  • Monthly
Learn MoreGet Job Support
Course Schedule
NameDates
Selenium Training Dec 24 to Jan 08View Details
Selenium Training Dec 28 to Jan 12View Details
Selenium Training Dec 31 to Jan 15View Details
Selenium Training Jan 04 to Jan 19View Details
Last updated: 28 Sep 2024
About Author

 

Madhuri is a Senior Content Creator at MindMajix. She has written about a range of different topics on various technologies, which include, Splunk, Tensorflow, Selenium, and CEH. She spends most of her time researching on technology, and startups. Connect with her via LinkedIn and Twitter .

read less
  1. Share:
Selenium Articles