0% found this document useful (0 votes)
17 views

Xpath and CSS Selector Cheat Sheet

The document provides a cheat sheet comparing XPath and CSS selectors. It lists common selectors and their uses for selecting elements on a webpage like images, links, classes, ids and attributes. It also includes some important HTML tags and their uses.

Uploaded by

MuthuKumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Xpath and CSS Selector Cheat Sheet

The document provides a cheat sheet comparing XPath and CSS selectors. It lists common selectors and their uses for selecting elements on a webpage like images, links, classes, ids and attributes. It also includes some important HTML tags and their uses.

Uploaded by

MuthuKumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Xpath and CSS Cheat Sheet

Description Xpath CSS Selector


Whole WebPage /html html
Whole WebPage /html/body 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
Attribute //tagname[@attribute-name=’value1′] tagName[attribute=Value of attribute]

Multiple //input[@type='submit' and tagname[attribute1='value1'][attribute2


Attributes @name='btnLogin'] ='value2']
Contains //*[contains(@type,'sub')] <HTML tag><[attribute*=sub string]>
Starts with //tagname[starts-with(@attribute, <HTML tag><[attribute^=prefix of the
‘Start value’)] string]>
Ends with //tagname[ends-with(@attribute, ‘End <HTML tag><[attribute$=suffix of the
value’)] 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'] N/A
Element //E2/preceding-sibling::E1 N/A
preceding some
sibling
Sibling element //E/preceding-sibling::*[1] N/A
immediately
preceding
User interface //E[@disabled] E:disabled
element that is
disabled
Checkbox (or //*[@checked] *:checked
radio button) that
is checked
Text Value //td[text()=‘textname'] N/A
Important Tagname and their Description
Tag Name Specification
<ul> Defines an unordered list of items.
<tr> Defines a row of cells in a table.
<title> Represents title to an HTML document.

<th> Used for creates header of a group of


cell in HTML table.
<table> Used to defines a table in an HTML
document.
<tbody> Used for grouping table rows.
<td> Used for creates standard data cell in
HTML table.
<span> Used to grouping and applying styles to
inline elements.
<section> Used to divide a document into number
of different generic section.
<select> Used to create a drop-down list.
<menu> Used to display a unordered list of
items/menu of commands.
<li> Define a list item either ordered list or
unordered list.
<iframe> Defines a inline frame that embedded
external content into current web
document.
<img> Used to insert image into a web
document.
<input> Define a get information in selected
input
<div> Define a division part
<body> Defines a main section(body) part in
HTML document
<br /> Specific a single line break
<button> Specifies a press/push button
<a> Specific a anchor (Hyperlink)

You might also like