Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->101.0.4951.15<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->101.0.4951.41<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->15.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->98.0.2<!-- GEN:stop --> | ✅ | ✅ | ✅ |

Expand Down
12 changes: 12 additions & 0 deletions playwright/_impl/_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,18 @@ def last(self) -> "Locator":
def nth(self, index: int) -> "Locator":
return Locator(self._frame, f"{self._selector} >> nth={index}")

def that(
self,
has_text: Union[str, Pattern] = None,
has: "Locator" = None,
) -> "Locator":
return Locator(
self._frame,
self._selector,
has_text=has_text,
has=has,
)

async def focus(self, timeout: float = None) -> None:
params = locals_to_params(locals())
return await self._frame.focus(self._selector, strict=True, **params)
Expand Down
100 changes: 81 additions & 19 deletions playwright/async_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,10 @@ async def select_text(
This method waits for [actionability](https://playwright.dev/python/docs/actionability) checks, then focuses the element and selects all its text
content.

If the element is inside the `<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), focuses and selects text in the
control instead.

Parameters
----------
force : Union[bool, NoneType]
Expand All @@ -2145,7 +2149,10 @@ async def select_text(
async def input_value(self, *, timeout: float = None) -> str:
"""ElementHandle.input_value

Returns `input.value` for `<input>` or `<textarea>` or `<select>` element. Throws for non-input elements.
Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element.

Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), returns the value of the control.

Parameters
----------
Expand Down Expand Up @@ -2180,12 +2187,14 @@ async def set_input_files(
) -> NoneType:
"""ElementHandle.set_input_files

This method expects `elementHandle` to point to an
[input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).

Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.

This method expects [`elementHandle`] to point to an
[input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). However, if the element is inside the
`<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), targets the control instead.

Parameters
----------
files : Union[List[Union[pathlib.Path, str]], List[{name: str, mimeType: str, buffer: bytes}], pathlib.Path, str, {name: str, mimeType: str, buffer: bytes}]
Expand Down Expand Up @@ -4775,7 +4784,10 @@ async def input_value(
) -> str:
"""Frame.input_value

Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element. Throws for non-input elements.
Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element.

Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), returns the value of the control.

Parameters
----------
Expand Down Expand Up @@ -4820,12 +4832,14 @@ async def set_input_files(
) -> NoneType:
"""Frame.set_input_files

This method expects `selector` to point to an
[input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).

Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.

This method expects `selector` to point to an
[input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). However, if the element is inside the
`<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), targets the control instead.

Parameters
----------
selector : str
Expand Down Expand Up @@ -7530,8 +7544,8 @@ async def goto(
) -> typing.Optional["Response"]:
"""Page.goto

Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
last redirect.
Returns the main resource response. In case of multiple redirects, the navigation will resolve with the first
non-redirect response.

The method will throw an error if:
- there's an SSL error (e.g. in case of self-signed certificates).
Expand Down Expand Up @@ -8977,7 +8991,10 @@ async def input_value(
) -> str:
"""Page.input_value

Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element. Throws for non-input elements.
Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element.

Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), returns the value of the control.

Parameters
----------
Expand Down Expand Up @@ -9022,12 +9039,14 @@ async def set_input_files(
) -> NoneType:
"""Page.set_input_files

This method expects `selector` to point to an
[input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).

Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.

This method expects `selector` to point to an
[input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). However, if the element is inside the
`<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), targets the control instead.

Parameters
----------
selector : str
Expand Down Expand Up @@ -12985,6 +13004,37 @@ def nth(self, index: int) -> "Locator":

return mapping.from_impl(self._impl_obj.nth(index=index))

def that(
self,
*,
has_text: typing.Union[str, typing.Pattern] = None,
has: "Locator" = None
) -> "Locator":
"""Locator.that

This method narrows existing locator according to the options, for example filters by text.

Parameters
----------
has_text : Union[Pattern, str, NoneType]
Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
[string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches
`<article><div>Playwright</div></article>`.
has : Union[Locator, NoneType]
Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
For example, `article` that has `text=Playwright` matches `<article><div>Playwright</div></article>`.

Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s.

Returns
-------
Locator
"""

return mapping.from_impl(
self._impl_obj.that(has_text=has_text, has=has._impl_obj if has else None)
)

async def focus(self, *, timeout: float = None) -> NoneType:
"""Locator.focus

Expand Down Expand Up @@ -13196,7 +13246,10 @@ async def inner_text(self, *, timeout: float = None) -> str:
async def input_value(self, *, timeout: float = None) -> str:
"""Locator.input_value

Returns `input.value` for `<input>` or `<textarea>` or `<select>` element. Throws for non-input elements.
Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element.

Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), returns the value of the control.

Parameters
----------
Expand Down Expand Up @@ -13580,6 +13633,10 @@ async def select_text(
This method waits for [actionability](https://playwright.dev/python/docs/actionability) checks, then focuses the element and selects all its text
content.

If the element is inside the `<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), focuses and selects text in the
control instead.

Parameters
----------
force : Union[bool, NoneType]
Expand Down Expand Up @@ -13611,12 +13668,14 @@ async def set_input_files(
) -> NoneType:
"""Locator.set_input_files

This method expects `element` to point to an
[input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).

Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.

This method expects [`locator`] to point to an
[input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). However, if the element is inside the
`<label>` element that has an associated
[control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), targets the control instead.

Parameters
----------
files : Union[List[Union[pathlib.Path, str]], List[{name: str, mimeType: str, buffer: bytes}], pathlib.Path, str, {name: str, mimeType: str, buffer: bytes}]
Expand Down Expand Up @@ -15491,7 +15550,10 @@ async def not_to_be_checked(self, *, timeout: float = None) -> NoneType:
async def to_be_disabled(self, *, timeout: float = None) -> NoneType:
"""LocatorAssertions.to_be_disabled

Ensures the `Locator` points to a disabled element.
Ensures the `Locator` points to a disabled element. Element is disabled if it has \"disabled\" attribute or is disabled
via ['aria-disabled'](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled). Note
that only native control elements such as HTML `button`, `input`, `select`, `textarea`, `option`, `optgroup` can be
disabled by setting \"disabled\" attribute. \"disabled\" attribute on other elements is ignored by the browser.

```py
from playwright.async_api import expect
Expand Down
Loading