@@ -3222,7 +3222,7 @@ def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any:
3222
3222
`ElementHandle` instances can be passed as an argument to the `frame.evaluate()`:
3223
3223
3224
3224
```py
3225
- body_handle = frame.query_selector (\"body\")
3225
+ body_handle = frame.evaluate (\"document. body\")
3226
3226
html = frame.evaluate(\"([body, suffix]) => body.innerHTML + suffix\", [body_handle, \"hello\"])
3227
3227
body_handle.dispose()
3228
3228
```
@@ -3309,6 +3309,8 @@ def query_selector(
3309
3309
3310
3310
Returns the ElementHandle pointing to the frame element.
3311
3311
3312
+ > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects and web-first assertions instead.
3313
+
3312
3314
The method finds an element matching the specified selector within the frame. See
3313
3315
[Working with selectors](./selectors.md) for more details. If no elements match the selector, returns `null`.
3314
3316
@@ -3337,6 +3339,8 @@ def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]:
3337
3339
3338
3340
Returns the ElementHandles pointing to the frame elements.
3339
3341
3342
+ > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects instead.
3343
+
3340
3344
The method finds all elements matching the specified selector within the frame. See
3341
3345
[Working with selectors](./selectors.md) for more details. If no elements match the selector, returns empty array.
3342
3346
@@ -3370,6 +3374,9 @@ def wait_for_selector(
3370
3374
Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
3371
3375
`detached`.
3372
3376
3377
+ > NOTE: Playwright automatically waits for element to be ready before performing an action. Using `Locator` objects and
3378
+ web-first assertions make the code wait-for-selector-free.
3379
+
3373
3380
Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
3374
3381
the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
3375
3382
selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
@@ -3707,6 +3714,9 @@ def eval_on_selector(
3707
3714
3708
3715
Returns the return value of `expression`.
3709
3716
3717
+ > NOTE: This method does not wait for the element to pass actionability checks and therefore can lead to the flaky
3718
+ tests. Use `locator.evaluate()`, other `Locator` helper methods or web-first assertions instead.
3719
+
3710
3720
The method finds an element matching the specified selector within the frame and passes it as a first argument to
3711
3721
`expression`. See [Working with selectors](./selectors.md) for more details. If no elements match the selector, the
3712
3722
method throws an error.
@@ -3759,6 +3769,9 @@ def eval_on_selector_all(
3759
3769
3760
3770
Returns the return value of `expression`.
3761
3771
3772
+ > NOTE: In most cases, `locator.evaluate_all()`, other `Locator` helper methods and web-first assertions do a
3773
+ better job.
3774
+
3762
3775
The method finds all elements matching the specified selector within the frame and passes an array of matched elements
3763
3776
as a first argument to `expression`. See [Working with selectors](./selectors.md) for more details.
3764
3777
@@ -5373,11 +5386,11 @@ def run(playwright):
5373
5386
page.set_content('<div><button>Click me</button></div>')
5374
5387
5375
5388
# Use the selector prefixed with its name.
5376
- button = page.query_selector ('tag=button')
5389
+ button = page.locator ('tag=button')
5377
5390
# Combine it with other selector engines.
5378
5391
page.click('tag=div >> text=\"Click me\"')
5379
5392
# Can use it in any methods supporting selectors.
5380
- button_count = page.eval_on_selector_all ('tag=button', 'buttons => buttons.length' )
5393
+ button_count = page.locator ('tag=button').count( )
5381
5394
print(button_count)
5382
5395
browser.close()
5383
5396
@@ -6309,8 +6322,10 @@ def query_selector(
6309
6322
) -> typing.Optional["ElementHandle"]:
6310
6323
"""Page.query_selector
6311
6324
6325
+ > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects and web-first assertions instead.
6326
+
6312
6327
The method finds an element matching the specified selector within the page. If no elements match the selector, the
6313
- return value resolves to `null`. To wait for an element on the page, use `page.wait_for_selector ()`.
6328
+ return value resolves to `null`. To wait for an element on the page, use `locator.wait_for ()`.
6314
6329
6315
6330
Shortcut for main frame's `frame.query_selector()`.
6316
6331
@@ -6337,6 +6352,8 @@ def query_selector(
6337
6352
def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]:
6338
6353
"""Page.query_selector_all
6339
6354
6355
+ > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects and web-first assertions instead.
6356
+
6340
6357
The method finds all elements matching the specified selector within the page. If no elements match the selector, the
6341
6358
return value resolves to `[]`.
6342
6359
@@ -6372,6 +6389,9 @@ def wait_for_selector(
6372
6389
Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
6373
6390
`detached`.
6374
6391
6392
+ > NOTE: Playwright automatically waits for element to be ready before performing an action. Using `Locator` objects and
6393
+ web-first assertions make the code wait-for-selector-free.
6394
+
6375
6395
Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
6376
6396
the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
6377
6397
selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
@@ -6727,7 +6747,7 @@ def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any:
6727
6747
`ElementHandle` instances can be passed as an argument to the `page.evaluate()`:
6728
6748
6729
6749
```py
6730
- body_handle = page.query_selector (\"body\")
6750
+ body_handle = page.evaluate (\"document. body\")
6731
6751
html = page.evaluate(\"([body, suffix]) => body.innerHTML + suffix\", [body_handle, \"hello\"])
6732
6752
body_handle.dispose()
6733
6753
```
@@ -6819,6 +6839,9 @@ def eval_on_selector(
6819
6839
) -> typing.Any:
6820
6840
"""Page.eval_on_selector
6821
6841
6842
+ > NOTE: This method does not wait for the element to pass actionability checks and therefore can lead to the flaky
6843
+ tests. Use `locator.evaluate()`, other `Locator` helper methods or web-first assertions instead.
6844
+
6822
6845
The method finds an element matching the specified selector within the page and passes it as a first argument to
6823
6846
`expression`. If no elements match the selector, the method throws an error. Returns the value of `expression`.
6824
6847
@@ -6870,6 +6893,9 @@ def eval_on_selector_all(
6870
6893
) -> typing.Any:
6871
6894
"""Page.eval_on_selector_all
6872
6895
6896
+ > NOTE: In most cases, `locator.evaluate_all()`, other `Locator` helper methods and web-first assertions do a
6897
+ better job.
6898
+
6873
6899
The method finds all elements matching the specified selector within the page and passes an array of matched elements as
6874
6900
a first argument to `expression`. Returns the result of `expression` invocation.
6875
6901
0 commit comments