Different approach to create XPath and CSS Selector
Whole WebPage -> /html --> html
Whole WebPage -> body --> /html/body body
image --> element --> //img img
Link ---> //a[@href = 'url'] --> a[href = 'url']
Direct Child //div/a div > a
Id --->//tagName[@id=’idValue’] tagName#idValue
Class --->//tagName[@class=’classValue’]
[tagName.Value of Class]
Attribute---> //tagname[@attributename=’value1′]
tagName[attribute=Value of attribute]
Multiple Attributes //input[@type='submit' and @name='btnLogin']
tagname[attribute1='value1'][attribute2='value2']
Contains //[contains(@type,'sub')]
<HTML tag <[attribute=subString]>
Starts with //tagname[startswith(@attribute, ‘Start value’)]
Ends with //tagname[endswith(@attribute, ‘End value’)]
<[attribute$=suffix of the String]>
Matches --> //[matches(@type,'value')] N/A
First Child --> //ul[@id=’list’]/li[1] ul#list li:first-child
Last Child --> //ul[@id=’list’]/li[last()] ul#list li:last-child
nth Child --> //ul[@id=’list’]/li[3] ul#list li:nth-child(3)
Text Value --> //td[text()=‘textname']
Element preceding some sibling --->//E2/preceding-sibling::E1
Sibling element immediately preceding--->//E/preceding-sibling::*1
User interface element that is disabled - //E[@disabled]E:disabled
Checkbox---> (radio button) that is checked //[@checked]*:checked
Text Value ---> //td[text()=‘textname']
Top comments (0)