---
id: selectors
title: "Element selectors"
---
Selectors are strings that point to the elements in the page. They are used to perform actions on those
elements by means of methods such as [`method: Page.click`], [`method: Page.fill`] and alike. All those
methods accept [`param: selector`] as their first argument.
## Quick guide
- Text selector
```js
await page.click('text=Log in');
```
```java
page.click("text=Log in");
```
```python async
await page.click("text=Log in")
```
```python sync
page.click("text=Log in")
```
Learn more about [text selector][text].
- CSS selector
```js
await page.click('button');
await page.click('#nav-bar .contact-us-item');
```
```java
page.click("button");
page.click("#nav-bar .contact-us-item");
```
```python async
await page.click("button")
await page.click("#nav-bar .contact-us-item")
```
```python sync
page.click("button")
page.click("#nav-bar .contact-us-item")
```
Learn more about [css selector][css].
- Select by attribute, with css selector
```js
await page.click('[data-test=login-button]');
await page.click('[aria-label="Sign in"]');
```
```java
page.click("[data-test=login-button]");
page.click("[aria-label='Sign in']");
```
```python async
await page.click("[data-test=login-button]")
await page.click("[aria-label='Sign in']")
```
```python sync
page.click("[data-test=login-button]")
page.click("[aria-label='Sign in']")
```
Learn more about [css selector][css].
- Combine css and text selectors
```js
await page.click('article:has-text("Playwright")');
await page.click('#nav-bar :text("Contact us")');
```
```java
page.click("article:has-text(\"Playwright\")");
page.click("#nav-bar :text(\"Contact us\")");
```
```python async
await page.click("article:has-text('Playwright')")
await page.click("#nav-bar :text('Contact us')")
```
```python sync
page.click("article:has-text('Playwright')")
page.click("#nav-bar :text('Contact us')")
```
Learn more about [`:has-text()` and `:text()` pseudo classes][text].
- Element that contains another, with css selector
```js
await page.click('.item-description:has(.item-promo-banner)');
```
```java
page.click(".item-description:has(.item-promo-banner)");
```
```python async
await page.click(".item-description:has(.item-promo-banner)")
```
```python sync
page.click(".item-description:has(.item-promo-banner)")
```
Learn more about [`:has()` pseudo class](#selecting-elements-that-contain-other-elements).
- Selecting based on layout, with css selector
```js
await page.click('input:right-of(:text("Username"))');
```
```java
page.click("input:right-of(:text(\"Username\"))");
```
```python async
await page.click("input:right-of(:text('Username'))")
```
```python sync
page.click("input:right-of(:text('Username'))")
```
Learn more about [layout selectors](#selecting-elements-based-on-layout).
- Only visible elements, with css selector
```js
await page.click('.login-button:visible');
```
```java
page.click(".login-button:visible");
```
```python async
await page.click(".login-button:visible")
```
```python sync
page.click(".login-button:visible")
```
Learn more about [`:visible` pseudo-class](#selecting-visible-elements).
- Pick n-th match
```js
await page.click(':nth-match(:text("Buy"), 3)');
```
```java
page.click(":nth-match(:text('Buy'), 3)");
```
```python async
await page.click(":nth-match(:text('Buy'), 3)"
```
```python sync
page.click(":nth-match(:text('Buy'), 3)"
```
Learn more about [`:nth-match()` pseudo-class](#pick-n-th-match-from-the-query-result).
- XPath selector
```js
await page.click('xpath=//button');
```
```java
page.click("xpath=//button");
```
```python async
await page.click("xpath=//button")
```
```python sync
page.click("xpath=//button")
```
Learn more about [XPath selector][xpath].
## Text selector
Text selector locates elements that contain passed text.
```js
await page.click('text=Log in');
```
```java
page.click("text=Log in");
```
```python async
await page.click("text=Log in")
```
```python sync
page.click("text=Log in")
```
Text selector has a few variations:
- `text=Log in` - default matching is case-insensitive and searches for a substring. For example, `text=Log` matches ``.
```js
await page.click('text=Log in');
```
```java
page.click("text=Log in");
```
```python async
await page.click("text=Log in")
```
```python sync
page.click("text=Log in")
```
- `text="Log in"` - text body can be escaped with single or double quotes to search for a text node with exact content. For example, `text="Log"` does not match `` because `