> For the complete documentation index, see [llms.txt](https://qatesting.gitbook.io/qa/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://qatesting.gitbook.io/qa/automation-testing/flow/selenium/selenium-webdriver/webdriver-commands/webelement/locators.md).

# Locators

## **Locators**

Locators are used to identify web elements on a web page. They are used by WebDriver commands to find web elements.

{% hint style="info" %}
💡 Selenium command to operate on GUI elements; right-click the cursor anywhere to access the “Inspect” option
{% endhint %}

<table data-full-width="true"><thead><tr><th width="178.33333333333337">Locator Type</th><th>Description</th><th>Java Example</th></tr></thead><tbody><tr><td>ID</td><td>Locates an element by its unique ID attribute</td><td><code>driver.findElement(</code><a href="http://by.id/(%22elementId%22)"><code>http://by.id/("elementId")</code></a><code>);</code></td></tr><tr><td>Class Name</td><td>Locates elements by matching the CSS class name</td><td><code>driver.findElement(By.className("className"));</code></td></tr><tr><td>Name</td><td>Locates elements by the name attribute</td><td><code>driver.findElement(</code><a href="http://by.name/(%22elementName%22)"><code>http://by.name/("elementName")</code></a><code>);</code></td></tr><tr><td>Tag Name</td><td>Locates elements by the HTML tag name</td><td><code>driver.findElement(By.tagName("tagName"));</code></td></tr><tr><td>Link Text</td><td>Locates anchor elements with exact link text</td><td><code>driver.findElement(By.linkText("linkText"));</code></td></tr><tr><td>Partial Link Text</td><td>Locates anchor elements with partial link text</td><td><code>driver.findElement(By.partialLinkText("partialLinkText"));</code></td></tr><tr><td>CSS Selector</td><td>Locates elements using CSS selectors</td><td><code>driver.findElement(By.cssSelector("cssSelector"));</code></td></tr><tr><td>XPath</td><td>Locates elements using XPath expressions</td><td><code>driver.findElement(By.xpath("xpathExpression"));</code></td></tr></tbody></table>
