@@ -3222,7 +3222,7 @@ def evaluate(self, expression: str, arg: typing.Any = None) -> typing.Any:
32223222 `ElementHandle` instances can be passed as an argument to the `frame.evaluate()`:
32233223
32243224 ```py
3225- body_handle = frame.query_selector (\"body\")
3225+ body_handle = frame.evaluate (\"document. body\")
32263226 html = frame.evaluate(\"([body, suffix]) => body.innerHTML + suffix\", [body_handle, \"hello\"])
32273227 body_handle.dispose()
32283228 ```
@@ -3309,6 +3309,8 @@ def query_selector(
33093309
33103310 Returns the ElementHandle pointing to the frame element.
33113311
3312+ > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects and web-first assertions instead.
3313+
33123314 The method finds an element matching the specified selector within the frame. See
33133315 [Working with selectors](./selectors.md) for more details. If no elements match the selector, returns `null`.
33143316
@@ -3337,6 +3339,8 @@ def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]:
33373339
33383340 Returns the ElementHandles pointing to the frame elements.
33393341
3342+ > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects instead.
3343+
33403344 The method finds all elements matching the specified selector within the frame. See
33413345 [Working with selectors](./selectors.md) for more details. If no elements match the selector, returns empty array.
33423346
@@ -3370,6 +3374,9 @@ def wait_for_selector(
33703374 Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
33713375 `detached`.
33723376
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+
33733380 Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
33743381 the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
33753382 selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
@@ -3707,6 +3714,9 @@ def eval_on_selector(
37073714
37083715 Returns the return value of `expression`.
37093716
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+
37103720 The method finds an element matching the specified selector within the frame and passes it as a first argument to
37113721 `expression`. See [Working with selectors](./selectors.md) for more details. If no elements match the selector, the
37123722 method throws an error.
@@ -3759,6 +3769,9 @@ def eval_on_selector_all(
37593769
37603770 Returns the return value of `expression`.
37613771
3772+ > NOTE: In most cases, `locator.evaluate_all()`, other `Locator` helper methods and web-first assertions do a
3773+ better job.
3774+
37623775 The method finds all elements matching the specified selector within the frame and passes an array of matched elements
37633776 as a first argument to `expression`. See [Working with selectors](./selectors.md) for more details.
37643777
@@ -5373,11 +5386,11 @@ def run(playwright):
53735386 page.set_content('<div><button>Click me</button></div>')
53745387
53755388 # Use the selector prefixed with its name.
5376- button = page.query_selector ('tag=button')
5389+ button = page.locator ('tag=button')
53775390 # Combine it with other selector engines.
53785391 page.click('tag=div >> text=\"Click me\"')
53795392 # 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( )
53815394 print(button_count)
53825395 browser.close()
53835396
@@ -6309,8 +6322,10 @@ def query_selector(
63096322 ) -> typing.Optional["ElementHandle"]:
63106323 """Page.query_selector
63116324
6325+ > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects and web-first assertions instead.
6326+
63126327 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 ()`.
63146329
63156330 Shortcut for main frame's `frame.query_selector()`.
63166331
@@ -6337,6 +6352,8 @@ def query_selector(
63376352 def query_selector_all(self, selector: str) -> typing.List["ElementHandle"]:
63386353 """Page.query_selector_all
63396354
6355+ > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects and web-first assertions instead.
6356+
63406357 The method finds all elements matching the specified selector within the page. If no elements match the selector, the
63416358 return value resolves to `[]`.
63426359
@@ -6372,6 +6389,9 @@ def wait_for_selector(
63726389 Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
63736390 `detached`.
63746391
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+
63756395 Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
63766396 the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
63776397 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:
67276747 `ElementHandle` instances can be passed as an argument to the `page.evaluate()`:
67286748
67296749 ```py
6730- body_handle = page.query_selector (\"body\")
6750+ body_handle = page.evaluate (\"document. body\")
67316751 html = page.evaluate(\"([body, suffix]) => body.innerHTML + suffix\", [body_handle, \"hello\"])
67326752 body_handle.dispose()
67336753 ```
@@ -6819,6 +6839,9 @@ def eval_on_selector(
68196839 ) -> typing.Any:
68206840 """Page.eval_on_selector
68216841
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+
68226845 The method finds an element matching the specified selector within the page and passes it as a first argument to
68236846 `expression`. If no elements match the selector, the method throws an error. Returns the value of `expression`.
68246847
@@ -6870,6 +6893,9 @@ def eval_on_selector_all(
68706893 ) -> typing.Any:
68716894 """Page.eval_on_selector_all
68726895
6896+ > NOTE: In most cases, `locator.evaluate_all()`, other `Locator` helper methods and web-first assertions do a
6897+ better job.
6898+
68736899 The method finds all elements matching the specified selector within the page and passes an array of matched elements as
68746900 a first argument to `expression`. Returns the result of `expression` invocation.
68756901
0 commit comments