kaliiiiiiiiii / undetected-playwright-python

Undetected Python version of the Playwright testing and automation library.

Home Page:https://playwright.dev/python/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] (Action) Selectors do not Work after Manual Content Setting

Vinyzu opened this issue · comments

Source code

  • I provided exact source code that allows reproducing the issue locally.

Test file (self-contained)

import asyncio

# undetected-playwright here!
from playwright.async_api import async_playwright, Playwright

async def run(playwright: Playwright):
    args = []

    # disable navigator.webdriver:true flag
    args.append("--disable-blink-features=AutomationControlled")
    browser = await playwright.chromium.launch(headless=False,
                                               args=args)

    context = await browser.new_context()
    page = await context.new_page()
    await page.goto("https://raw.githack.com/microsoft/playwright-python/main/tests/assets/empty.html")
    await page.set_content('<a href="https://raw.githack.com/microsoft/playwright-python/main/tests/assets/one-style.html">yo</a>')
    await page.click("a")
    await page.wait_for_timeout(10000)

async def main():
    async with async_playwright() as playwright:
        await run(playwright)


if __name__ == "__main__":
    loop = asyncio.ProactorEventLoop()
    loop.run_until_complete(main())

Expected

The Selector should be able to pick up the new inserted content, like it is the case with "normal" playwright.

Actual

The Selector doesnt pick up the new content.
Note: Could be explained by a missing isolatedContext consideration.

Note:

await page.locator("a").click()

Works as expected.

Note no.1:

await page.set_content('<iframe src="demo_iframe.htm" height="200" width="300" title="Iframe Example"></iframe> ')
print(page.frame_locator('[title="Iframe Example"]'))

Also doesnt work. Other Functions including Selectors maight also not be expected to work

relevant source code here:

and locator source:

  • def locator(
    self,
    selector: str,
    has_text: Union[str, Pattern[str]] = None,
    has_not_text: Union[str, Pattern[str]] = None,
    has: "Locator" = None,
    has_not: "Locator" = None,
    ) -> "Locator":
    return self._main_frame.locator(
    selector,
    has_text=has_text,
    has_not_text=has_not_text,
    has=has,
    has_not=has_not,
    )
  • async def click(
    self,
    modifiers: List[KeyboardModifier] = None,
    position: Position = None,
    delay: float = None,
    button: MouseButton = None,
    clickCount: int = None,
    timeout: float = None,
    force: bool = None,
    noWaitAfter: bool = None,
    trial: bool = None,
    ) -> None:
    params = locals_to_params(locals())
    return await self._frame.click(self._selector, strict=True, **params)
  • async def click(
    self,
    selector: str,
    modifiers: List[KeyboardModifier] = None,
    position: Position = None,
    delay: float = None,
    button: MouseButton = None,
    clickCount: int = None,
    timeout: float = None,
    force: bool = None,
    noWaitAfter: bool = None,
    trial: bool = None,
    strict: bool = None,
    ) -> None:
    return await self._main_frame.click(**locals_to_params(locals()))
  • async def click(
    self,
    selector: str,
    modifiers: List[KeyboardModifier] = None,
    position: Position = None,
    delay: float = None,
    button: MouseButton = None,
    clickCount: int = None,
    timeout: float = None,
    force: bool = None,
    noWaitAfter: bool = None,
    strict: bool = None,
    trial: bool = None,
    ) -> None:
    await self._channel.send("click", locals_to_params(locals()))