In ScraperSensei, you can inspect the element by clicking the “Inspect Element” button in the left of the input area.

Selector is helpful for locating the specific element you want to interact with.

You can fill any valid CSS selector or use the built-in selector tool to select the element.

We also provide some utility functions to help you get the selector of the element, as follows:

.filter()

This method narrows existing locator according to the options, for example filters by text. It can be chained to filter multiple times.

filter(has_text="text in column 1").filter(
    has=get_by_role("button", name="column 2 button")
)

Arguments:

  • has_text: The text to filter by.
  • has_not_text: The text to filter by.
  • has: The element to filter by.
  • has_not: The element to filter by.

get_by_alt_text

Allows locating elements by their alt text.

Usage

For example, this method will find the image by alt text “Playwright logo”:

<img alt="Playwright logo" />
get_by_alt_text("Playwright logo")

get_by_label

Allows locating input elements by the text of the associated <label> or aria-labelledby element, or by the aria-label attribute.

For example, this method will find inputs by label “Username” and “Password” in the following DOM:

<input aria-label="Username">
<label for="password-input">Password:</label>
<input id="password-input">

Usage

get_by_label("Username")
# or
get_by_label("Password")

get_by_placeholder

Allows locating input elements by their placeholder attribute.

For example, consider the following DOM structure.

<input type="email" placeholder="name@example.com" />

You can locate the input element by its placeholder:

get_by_placeholder("name@example.com")

get_by_role

Allows locating elements by their ARIA role, ARIA attributes and accessible name.

Usage

Consider the following DOM structure.

<h3>Sign up</h3>
<label>
  <input type="checkbox" /> Subscribe
</label>
<br/>
<button>Submit</button>

You can locate each element by it’s implicit role:

get_by_role("heading", name="Sign up")
# or
get_by_role("checkbox", name="Subscribe")
# or
get_by_role("button", name="Submit")

get_by_test_id

Locate element by the test id.

Usage

Consider the following DOM structure.

<button data-testid="directions">Itinéraire</button>

You can locate the button element by its test id:

get_by_test_id("directions")

get_by_text

Allows locating elements that contain given text.

See also .filter() that allows to match by another criteria, like an accessible role, and then filter by the text content.

Usage

Consider the following DOM structure:

Hello world
Hello

You can locate by text substring, exact string, or a regular expression:

# Matches <span>
get_by_text("world")
# Matches first <div>
get_by_text("Hello")
# Matches second <div>
get_by_text("Hello")
# Matches both <div>s
get_by_text(re.compile("Hello"))
# Matches second <div>
get_by_text(re.compile("^hello$", re.IGNORECASE))

get_by_title

Allows locating elements by their title or aria-label attribute.

Usage

Consider the following DOM structure.

<span title="Issues count">25 issues</span>

You can check the issues count after locating it by the title text:

get_by_title("Issues count")