Skip to content

Commit e209323

Browse files
committed
fix: query_selector strict mode
1 parent 1c86a35 commit e209323

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

playwright/_impl/_element_handle.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ async def select_option(
150150
dict(
151151
timeout=timeout,
152152
noWaitAfter=noWaitAfter,
153+
force=force,
153154
**convert_select_option_values(value, index, label, element)
154155
)
155156
)

playwright/_impl/_frame.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ async def query_selector(
259259
self, selector: str, strict: bool = None
260260
) -> Optional[ElementHandle]:
261261
return from_nullable_channel(
262-
await self._channel.send("querySelector", dict(selector=selector))
262+
await self._channel.send("querySelector", locals_to_params(locals()))
263263
)
264264

265265
async def query_selector_all(self, selector: str) -> List[ElementHandle]:
@@ -321,7 +321,13 @@ async def dispatch_event(
321321
) -> None:
322322
await self._channel.send(
323323
"dispatchEvent",
324-
dict(selector=selector, type=type, eventInit=serialize_argument(eventInit)),
324+
dict(
325+
selector=selector,
326+
type=type,
327+
eventInit=serialize_argument(eventInit),
328+
strict=strict,
329+
timeout=timeout,
330+
),
325331
)
326332

327333
async def eval_on_selector(
@@ -338,6 +344,7 @@ async def eval_on_selector(
338344
selector=selector,
339345
expression=expression,
340346
arg=serialize_argument(arg),
347+
strict=strict,
341348
),
342349
)
343350
)
@@ -549,6 +556,8 @@ async def select_option(
549556
selector=selector,
550557
timeout=timeout,
551558
noWaitAfter=noWaitAfter,
559+
strict=strict,
560+
force=force,
552561
**convert_select_option_values(value, index, label, element),
553562
)
554563
)

tests/async/test_browsercontext.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,4 +740,6 @@ async def test_strict_selectors_on_context(browser: Browser, server: Server):
740740
)
741741
with pytest.raises(Error):
742742
await page.text_content("button")
743+
with pytest.raises(Error):
744+
await page.query_selector("button")
743745
await context.close()

tests/async/test_frames.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
import asyncio
1616

17-
from playwright.async_api import Error
17+
import pytest
18+
19+
from playwright.async_api import Error, Page
20+
from tests.server import Server
1821

1922

2023
async def test_evaluate_handle(page, server):
@@ -253,3 +256,17 @@ async def test_should_report_different_frame_instance_when_frame_re_attaches(
253256
frame2 = await frame2_info.value
254257
assert frame2.is_detached() is False
255258
assert frame1 != frame2
259+
260+
261+
async def test_strict_mode(page: Page, server: Server):
262+
await page.goto(server.EMPTY_PAGE)
263+
await page.set_content(
264+
"""
265+
<button>Hello</button>
266+
<button>Hello</button>
267+
"""
268+
)
269+
with pytest.raises(Error):
270+
await page.text_content("button", strict=True)
271+
with pytest.raises(Error):
272+
await page.query_selector("button", strict=True)

0 commit comments

Comments
 (0)