DEV Community

Suresh Ayyanna
Suresh Ayyanna

Posted on

4 1 1 1 1

Selenium CheatSheet(xpath)

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']

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay