-
Notifications
You must be signed in to change notification settings - Fork 0
Find locators in 15 different ways
Why this Topic ?
-
Technology Independent
-
Selenium WebDriver - 2007
-
Cypress - 2014
-
Playwright - 2020
Common Locators :
-
ID
-
ClassName
-
Name
-
LinkText
-
CSS Selector
-
Xpath
Fundamental way to write CSS Selector
Id :
- HTMLTag#ID
- #Id
Class :
- HtmlTag.className
- .ClassName
- .ClassName1.ClassName2.ClassName3.
- HtmlTag.ClassName1.ClassName2.ClassName3
Way to write Xpath & CSS Selector
-
Xpath - //htmltag[@attr =’string’]
-
CSS - htmltag[attr=’string’]
Custom way to write XPATH & CSS Selector
-
Travel (Parent to Child)
-
Xpath = ParentTag/ChildTag
-
CSS = ParentTag>ChildTag (Immediate Child)
-
CSS = ParentTag ChildTag (Not Immediate Child)
- We can Simply achieve this while replacing the space with dot.
Suppose this is the Dom
<input class=’Test123’>
and the numeric value are changing every time.
- There are approch listed below :-
Syntax :- htmltag[attr^=’String’]
So we can write like this, input[class^=’Test’]
<input class=’423423Test’>
Syntax :- //htmltag[attr$=’Text’]
So we can write like this, //input[class$=’Test’]
Xpath - //htmltag[@attr= ‘val1’ and @attr2 =’val2’]
CSS - htmltag[attr1=’val1’][attr2=’val2’]
CSS Selector is not having contains methods but there is an alternate way
<input class=’423423Test123123’>
htmltag[attr*=’Text’]
So we can write like this, input [class=’Test’]*
XPath - Parent Child Travel approach
CSS Selector - ParentTag#StaticID>htmlTag:nth-of-type(Integer)