Finding Elements by XPATH
1. Finding elements by XPATH and ID
2. Finding elements by XPATH and NAME
3. Finding elements by XPATH and LINK
4. Finding elements by XPATH and Text
Finding elements by XPATH and ID:-
Finding elements by XPATH and NAME:-
Finding elements by XPATH and LINK:-
Partial Match on Attribute Content:-
There are times where only part of the ID is dynamic. For example, if you wanted to access the element that has the text “This element has an ID that changes every time the page is loaded” in it, you will use //div[contains(@id,’time_’)]. This is due to the first part of the ID always being static. The locator could also use starts-with instead of contains to make the XPath query stricter in what is returned.
We can use two methods to find the elements with text
Syntax:- //element[text()=’inner text’].
Example for Starts with: for link Booster seats
Example for contains: for link Car seat bases
Finding elements by the text they contain can be quite useful when working with web pages that have been created dynamically.
If we know part of the text then we have to use this command.
Syntax: //element[contains(text(),’inner text’)]
For the above example the command is :
//a[contains(text(),’Car Seat Bases’)]
Syntax:- //element[starts with(text(),’inner text’)]
If we know the starting of the text then we have to use this command.
For the above example the command is:
Finding Elements by using CSS
locators are a way to tell selenium which specific element we want it to act on Why CSS
//input[@id=”myId”] vs css=input#myId
//input[@class=”myClass”] vs css=input.myClass
//input[@name=”myName”] vs css=input[name=myName] //*[@id=”myId”] vs css=#myId
//table[@id=”myId”]//tr[@class=”myClass”]//td vs css=table#myId tr.myClass td:nth(3)
Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!
|Selenium Training||May 23 to Jun 07|
|Selenium Training||May 28 to Jun 12|
|Selenium Training||May 30 to Jun 14|
|Selenium Training||Jun 04 to Jun 19|
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 .
Copyright © 2013 - 2022 MindMajix Technologies