WHAT ARE ELEMENT LOCATORS
DIFFERENT ELEMENT LOCATORS IN SELENIUM
INTRODUCTION TO CSS SELECTORS
DEMO
www.edureka.co
SYNTAX AND BASIC COMMANDS
www.edureka.co
www.edureka.co
Locator can be termed as an address that identifies a web element uniquely within the webpage. Locators are the HTML properties
of a web element which tells the Selenium about the web element it needs to perform the action on.
www.edureka.co
www.edureka.co
www.edureka.co
XPATH
CSS SELECTOR LINK TEXT
ID NAME
PARTIAL LINK
CLASS
www.edureka.co
CSS Selector
Link Text
Partial link text
ID
Name
XPath
The Id strategy looks for an element in the page having
an id attribute corresponding to the specified pattern. <label
id="my_id" /> will be matched by a locator like id=my_id or
just my_id
Target Format: id=id of the element
www.edureka.co
CSS Selector
Link Text
Partial link text
ID
Name
XPath
Locating elements by name are very similar to locating by ID,
except that we use the "name=" prefix instead.
Target Format: name=name of the element
www.edureka.co
CSS Selector
Link Text
Partial link text
ID
Name
XPath
This type of locator applies only to hyperlink texts. We access
the link by prefixing our target with "link=" and then followed
by the hyperlink text.
Target Format: link=link_text
www.edureka.co
CSS Selector
Link Text
Partial link text
ID
Name
XPath
Locating by CSS Selector using an HTML tag and a class name
is similar to using a tag and ID, but in this case, a dot (.) is used
instead of a hash sign.
Target Format:css=tag.class[attribute=value]
www.edureka.co
CSS Selector
Link Text
Partial link text
ID
Name
XPath
In some situations, we may need to find links by a portion of the
text in a Link Text element. it contains. In such situations, we use
Partial Link Text to locate elements.
Syntax:
findElement(By.partialLinkText("partialLinkText"));
www.edureka.co
CSS Selector
Link Text
Partial link text
ID
Name
XPath is designed to allow the navigation of XML documents,
with the purpose of selecting individual elements, attributes, or
some other part of an XML document for specific processing.
Xpath=//tagname[@Attribute=‘Value’]
XPath
www.edureka.co
www.edureka.co
CSS Selector is the combination of an element selector and a selector value which identifies the web
element within a web page
www.edureka.co
CH
SYNTAX &
BASIC
COMMANDS
www.edureka.co
Select HTML tag
Symbolize ID
attribute
Value of an
attribute
CSS= <HTML Tag> <#> <AttributeValue> When ID is
present
CSS = <HTML Tag> <.> <AttributeValue>
Class attribute
When class is
present
CH
SYNTAX &
BASIC
COMMANDS
www.edureka.co
Partial values
HTML tag [ locator * = ‘value’ ]
For substrings,
HTML tag [ locator ^ = ‘value’ ]
HTML tag [ locator $ = ‘value’ ]
HTML tag <:> <contains> <(text)>
www.edureka.co
www.edureka.co

CSS Selector in Selenium WebDriver | Edureka