From cf009cd838404b3a93a5a80780f1f8e6ea89fc8e Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 26 Aug 2021 12:07:58 +0200 Subject: [PATCH] fix: query_selector strict mode --- playwright/_impl/_element_handle.py | 1 + playwright/_impl/_frame.py | 25 +++++++++++++++++++------ tests/async/test_browsercontext.py | 2 ++ tests/async/test_frames.py | 19 ++++++++++++++++++- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/playwright/_impl/_element_handle.py b/playwright/_impl/_element_handle.py index eb99884ba..5a8aaef7f 100644 --- a/playwright/_impl/_element_handle.py +++ b/playwright/_impl/_element_handle.py @@ -150,6 +150,7 @@ async def select_option( dict( timeout=timeout, noWaitAfter=noWaitAfter, + force=force, **convert_select_option_values(value, index, label, element) ) ) diff --git a/playwright/_impl/_frame.py b/playwright/_impl/_frame.py index a947d9cf1..4266e3195 100644 --- a/playwright/_impl/_frame.py +++ b/playwright/_impl/_frame.py @@ -259,7 +259,7 @@ async def query_selector( self, selector: str, strict: bool = None ) -> Optional[ElementHandle]: return from_nullable_channel( - await self._channel.send("querySelector", dict(selector=selector)) + await self._channel.send("querySelector", locals_to_params(locals())) ) async def query_selector_all(self, selector: str) -> List[ElementHandle]: @@ -321,7 +321,15 @@ async def dispatch_event( ) -> None: await self._channel.send( "dispatchEvent", - dict(selector=selector, type=type, eventInit=serialize_argument(eventInit)), + locals_to_params( + dict( + selector=selector, + type=type, + eventInit=serialize_argument(eventInit), + strict=strict, + timeout=timeout, + ), + ), ) async def eval_on_selector( @@ -334,10 +342,13 @@ async def eval_on_selector( return parse_result( await self._channel.send( "evalOnSelector", - dict( - selector=selector, - expression=expression, - arg=serialize_argument(arg), + locals_to_params( + dict( + selector=selector, + expression=expression, + arg=serialize_argument(arg), + strict=strict, + ) ), ) ) @@ -549,6 +560,8 @@ async def select_option( selector=selector, timeout=timeout, noWaitAfter=noWaitAfter, + strict=strict, + force=force, **convert_select_option_values(value, index, label, element), ) ) diff --git a/tests/async/test_browsercontext.py b/tests/async/test_browsercontext.py index c4b699c97..9ec565121 100644 --- a/tests/async/test_browsercontext.py +++ b/tests/async/test_browsercontext.py @@ -740,4 +740,6 @@ async def test_strict_selectors_on_context(browser: Browser, server: Server): ) with pytest.raises(Error): await page.text_content("button") + with pytest.raises(Error): + await page.query_selector("button") await context.close() diff --git a/tests/async/test_frames.py b/tests/async/test_frames.py index 9de915f94..633b74d87 100644 --- a/tests/async/test_frames.py +++ b/tests/async/test_frames.py @@ -14,7 +14,10 @@ import asyncio -from playwright.async_api import Error +import pytest + +from playwright.async_api import Error, Page +from tests.server import Server async def test_evaluate_handle(page, server): @@ -253,3 +256,17 @@ async def test_should_report_different_frame_instance_when_frame_re_attaches( frame2 = await frame2_info.value assert frame2.is_detached() is False assert frame1 != frame2 + + +async def test_strict_mode(page: Page, server: Server): + await page.goto(server.EMPTY_PAGE) + await page.set_content( + """ + + + """ + ) + with pytest.raises(Error): + await page.text_content("button", strict=True) + with pytest.raises(Error): + await page.query_selector("button", strict=True)