Skip to content

Selenium locators

MirekVales edited this page Mar 27, 2018 · 2 revisions

When testing with Selenium, the ability to identify a UI element you want to work with is crucial. A locator is a pattern that tells the engine which element attributes make identification possible and therefore which web elements should be processed by further commands.
Each locator starts with a locator type followed by a pattern.

Css - CSS selector locator

css=[css selector]

Example:
css=#header css=.button
css=tag:contains("inner text")

Identifier - Locating by unique ID

id=[element's id]

Example:
id=header

Link - Locating by link text

link=[link text]

Example:
link=DOWNLOAD

Name - Locating by element name

name=[element name]

Example:
name=Button1

TagName - Locating by tag name

tagname=[tag name]

Example:
tagname=input

XPath - Locating by XPath

xpath=[xpath selector]

Example:
xpath=//html/body/div

Locator Modifiers

Locator behavior may be changed by an optional modifier that prefixes the actual locator.
(?[modifier])[locator body]