@@ -706,7 +706,7 @@ async def fallback(
706
706
"""Route.fallback
707
707
708
708
When several routes match the given pattern, they run in the order opposite to their registration. That way the last
709
- registered route can always override all the previos ones. In the example below, request will be handled by the
709
+ registered route can always override all the previous ones. In the example below, request will be handled by the
710
710
bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first
711
711
registered route.
712
712
@@ -2426,7 +2426,7 @@ async def bounding_box(self) -> typing.Optional[FloatRect]:
2426
2426
This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is
2427
2427
calculated relative to the main frame viewport - which is usually the same as the browser window.
2428
2428
2429
- Scrolling affects the returned bonding box, similarly to
2429
+ Scrolling affects the returned bounding box, similarly to
2430
2430
[Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect). That
2431
2431
means `x` and/or `y` may be negative.
2432
2432
@@ -4451,7 +4451,11 @@ async def drag_and_drop(
4451
4451
Parameters
4452
4452
----------
4453
4453
source : str
4454
+ A selector to search for an element to drag. If there are multiple elements satisfying the selector, the first will be
4455
+ used. See [working with selectors](../selectors.md) for more details.
4454
4456
target : str
4457
+ A selector to search for an element to drop onto. If there are multiple elements satisfying the selector, the first will
4458
+ be used. See [working with selectors](../selectors.md) for more details.
4455
4459
source_position : Union[{x: float, y: float}, NoneType]
4456
4460
Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not
4457
4461
specified, some visible point of the element is used.
@@ -5302,7 +5306,7 @@ async def run(playwright):
5302
5306
# Use the selector prefixed with its name.
5303
5307
button = await page.query_selector('tag=button')
5304
5308
# Combine it with other selector engines.
5305
- await page.click ('tag=div >> text=\"Click me\"')
5309
+ await page.locator ('tag=div >> text=\"Click me\"').click( )
5306
5310
# Can use it in any methods supporting selectors.
5307
5311
button_count = await page.locator('tag=button').count()
5308
5312
print(button_count)
@@ -7764,7 +7768,7 @@ async def route_from_har(
7764
7768
relative path, then it is resolved relative to the current working directory.
7765
7769
url : Union[Pattern, str, NoneType]
7766
7770
A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
7767
- will be surved from the HAR file. If not specified, all requests are served from the HAR file.
7771
+ will be served from the HAR file. If not specified, all requests are served from the HAR file.
7768
7772
not_found : Union["abort", "fallback", NoneType]
7769
7773
- If set to 'abort' any request not found in the HAR file will be aborted.
7770
7774
- If set to 'fallback' missing requests will be sent to the network.
@@ -8498,7 +8502,11 @@ async def drag_and_drop(
8498
8502
Parameters
8499
8503
----------
8500
8504
source : str
8505
+ A selector to search for an element to drag. If there are multiple elements satisfying the selector, the first will be
8506
+ used. See [working with selectors](../selectors.md) for more details.
8501
8507
target : str
8508
+ A selector to search for an element to drop onto. If there are multiple elements satisfying the selector, the first will
8509
+ be used. See [working with selectors](../selectors.md) for more details.
8502
8510
source_position : Union[{x: float, y: float}, NoneType]
8503
8511
Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not
8504
8512
specified, some visible point of the element is used.
@@ -9723,7 +9731,7 @@ def on(
9723
9731
9724
9732
```py
9725
9733
async with context.expect_page() as page_info:
9726
- await page.click (\"a[target=_blank]\"),
9734
+ await page.locator (\"a[target=_blank]\").click( ),
9727
9735
page = await page_info.value
9728
9736
print(await page.evaluate(\"location.href\"))
9729
9737
```
@@ -9841,7 +9849,7 @@ def once(
9841
9849
9842
9850
```py
9843
9851
async with context.expect_page() as page_info:
9844
- await page.click (\"a[target=_blank]\"),
9852
+ await page.locator (\"a[target=_blank]\").click( ),
9845
9853
page = await page_info.value
9846
9854
print(await page.evaluate(\"location.href\"))
9847
9855
```
@@ -10269,7 +10277,7 @@ async def run(playwright):
10269
10277
<button onclick=\"onClick()\">Click me</button>
10270
10278
<div></div>
10271
10279
\"\"\")
10272
- await page.click (\"button\")
10280
+ await page.locator (\"button\").click( )
10273
10281
10274
10282
async def main():
10275
10283
async with async_playwright() as playwright:
@@ -10347,7 +10355,7 @@ async def run(playwright):
10347
10355
<button onclick=\"onClick()\">Click me</button>
10348
10356
<div></div>
10349
10357
\"\"\")
10350
- await page.click (\"button\")
10358
+ await page.locator (\"button\").click( )
10351
10359
10352
10360
async def main():
10353
10361
async with async_playwright() as playwright:
@@ -10500,7 +10508,7 @@ async def route_from_har(
10500
10508
relative path, then it is resolved relative to the current working directory.
10501
10509
url : Union[Pattern, str, NoneType]
10502
10510
A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
10503
- will be surved from the HAR file. If not specified, all requests are served from the HAR file.
10511
+ will be served from the HAR file. If not specified, all requests are served from the HAR file.
10504
10512
not_found : Union["abort", "fallback", NoneType]
10505
10513
- If set to 'abort' any request not found in the HAR file will be aborted.
10506
10514
- If set to 'fallback' falls through to the next route handler in the handler chain.
@@ -10526,7 +10534,7 @@ def expect_event(
10526
10534
10527
10535
```py
10528
10536
async with context.expect_event(\"page\") as event_info:
10529
- await page.click (\"button\")
10537
+ await page.locator (\"button\").click( )
10530
10538
page = await event_info.value
10531
10539
```
10532
10540
@@ -10823,13 +10831,22 @@ async def new_context(
10823
10831
10824
10832
Creates a new browser context. It won't share cookies/cache with other browser contexts.
10825
10833
10834
+ > NOTE: If directly using this method to create `BrowserContext`s, it is best practice to explicilty close the returned
10835
+ context via `browser_context.close()` when your code is done with the `BrowserContext`, and before calling
10836
+ `browser.close()`. This will ensure the `context` is closed gracefully and any artifacts—like HARs and
10837
+ videos—are fully flushed and saved.
10838
+
10826
10839
```py
10827
10840
browser = await playwright.firefox.launch() # or \"chromium\" or \"webkit\".
10828
10841
# create a new incognito browser context.
10829
10842
context = await browser.new_context()
10830
10843
# create a new page in a pristine context.
10831
10844
page = await context.new_page()
10832
10845
await page.goto(\"https://example.com\")
10846
+
10847
+ # gracefully close up everything
10848
+ await context.close()
10849
+ await browser.close()
10833
10850
```
10834
10851
10835
10852
Parameters
@@ -11181,6 +11198,10 @@ async def close(self) -> NoneType:
11181
11198
In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
11182
11199
browser server.
11183
11200
11201
+ > NOTE: This is similar to force quitting the browser. Therefore, you should call `browser_context.close()` on
11202
+ any `BrowserContext`'s you explicitly created earlier with `browser.new_context()` **before** calling
11203
+ `browser.close()`.
11204
+
11184
11205
The `Browser` object itself is considered to be disposed and cannot be used anymore.
11185
11206
"""
11186
11207
@@ -11950,7 +11971,7 @@ async def start_chunk(self, *, title: str = None) -> NoneType:
11950
11971
await page.goto(\"https://playwright.dev\")
11951
11972
11952
11973
await context.tracing.start_chunk()
11953
- await page.click (\"text=Get Started\")
11974
+ await page.locator (\"text=Get Started\").click( )
11954
11975
# Everything between start_chunk and stop_chunk will be recorded in the trace.
11955
11976
await context.tracing.stop_chunk(path = \"trace1.zip\")
11956
11977
@@ -12045,7 +12066,7 @@ async def bounding_box(
12045
12066
This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is
12046
12067
calculated relative to the main frame viewport - which is usually the same as the browser window.
12047
12068
12048
- Scrolling affects the returned bonding box, similarly to
12069
+ Scrolling affects the returned bounding box, similarly to
12049
12070
[Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect). That
12050
12071
means `x` and/or `y` may be negative.
12051
12072
@@ -14301,7 +14322,7 @@ async def to_have_url(
14301
14322
Parameters
14302
14323
----------
14303
14324
url_or_reg_exp : Union[Pattern, str]
14304
- Expected substring or RegExp.
14325
+ Expected URL string or RegExp.
14305
14326
timeout : Union[float, NoneType]
14306
14327
Time to retry the assertion for.
14307
14328
"""
@@ -14326,7 +14347,7 @@ async def not_to_have_url(
14326
14347
Parameters
14327
14348
----------
14328
14349
url_or_reg_exp : Union[Pattern, str]
14329
- Expected substring or RegExp.
14350
+ Expected URL string or RegExp.
14330
14351
timeout : Union[float, NoneType]
14331
14352
Time to retry the assertion for.
14332
14353
"""
@@ -14510,13 +14531,19 @@ async def to_have_class(
14510
14531
) -> NoneType:
14511
14532
"""LocatorAssertions.to_have_class
14512
14533
14513
- Ensures the `Locator` points to an element with given CSS class.
14534
+ Ensures the `Locator` points to an element with given CSS classes. This needs to be a full match or using a relaxed
14535
+ regular expression.
14536
+
14537
+ ```html
14538
+ <div class='selected row' id='component'></div>
14539
+ ```
14514
14540
14515
14541
```py
14516
14542
from playwright.async_api import expect
14517
14543
14518
14544
locator = page.locator(\"#component\")
14519
14545
await expect(locator).to_have_class(re.compile(r\"selected\"))
14546
+ await expect(locator).to_have_class(\"selected row\")
14520
14547
```
14521
14548
14522
14549
Note that if array is passed as an expected value, entire lists of elements can be asserted:
0 commit comments