Esempio n. 1
0
 async def press(
     self,
     selector: str,
     key: str,
     delay: int = None,
     timeout: int = None,
     noWaitAfter: bool = None,
 ) -> None:
     await self._channel.send("press", locals_to_params(locals()))
Esempio n. 2
0
 async def type(
     self,
     selector: str,
     text: str,
     delay: int = None,
     timeout: int = None,
     noWaitAfter: bool = None,
 ) -> None:
     await self._channel.send("type", locals_to_params(locals()))
Esempio n. 3
0
 async def addScriptTag(
     self,
     url: str = None,
     path: Union[str, Path] = None,
     content: str = None,
     type: str = None,
 ) -> ElementHandle:
     return await self._main_frame.addScriptTag(**locals_to_params(locals())
                                                )
Esempio n. 4
0
 async def hover(
     self,
     selector: str,
     modifiers: List[KeyboardModifier] = None,
     position: MousePosition = None,
     timeout: int = None,
     force: bool = None,
 ) -> None:
     await self._channel.send("hover", locals_to_params(locals()))
 async def hover(
     self,
     selector: str,
     modifiers: List[KeyboardModifier] = None,
     position: Dict = None,
     timeout: int = None,
     force: bool = None,
 ) -> None:
     return await self._main_frame.hover(**locals_to_params(locals()))
Esempio n. 6
0
 async def waitForSelector(
     self,
     selector: str,
     state: Literal["attached", "detached", "hidden", "visible"] = None,
     timeout: int = None,
 ) -> Optional["ElementHandle"]:
     return from_nullable_channel(
         await self._channel.send("waitForSelector", locals_to_params(locals()))
     )
 async def setInputFiles(
     self,
     files: Union[str, Path, FilePayload, List[str], List[Path], List[FilePayload]],
     timeout: int = None,
     noWaitAfter: bool = None,
 ) -> None:
     params = locals_to_params(locals())
     params["files"] = normalize_file_payloads(files)
     await self._channel.send("setInputFiles", params)
 async def type(
     self,
     selector: str,
     text: str,
     delay: int = None,
     timeout: int = None,
     noWaitAfter: bool = None,
 ) -> None:
     return await self._main_frame.type(**locals_to_params(locals()))
 async def setInputFiles(
     self,
     selector: str,
     files: Union[str, FilePayload, List[str], List[FilePayload]],
     timeout: int = None,
     noWaitAfter: bool = None,
 ) -> None:
     return await self._main_frame.setInputFiles(
         **locals_to_params(locals()))
Esempio n. 10
0
 async def press(
     self,
     selector: str,
     key: str,
     delay: int = None,
     timeout: int = None,
     noWaitAfter: bool = None,
 ) -> None:
     return await self._main_frame.press(**locals_to_params(locals()))
Esempio n. 11
0
 async def tap(
     self,
     selector: str,
     modifiers: List[KeyboardModifier] = None,
     position: MousePosition = None,
     timeout: int = None,
     force: bool = None,
     noWaitAfter: bool = None,
 ) -> None:
     return await self._main_frame.tap(**locals_to_params(locals()))
 async def addScriptTag(
     self,
     url: str = None,
     path: str = None,
     content: str = None,
     type: str = None,
 ) -> ElementHandle:
     return from_channel(await
                         self._channel.send("addScriptTag",
                                            locals_to_params(locals())))
Esempio n. 13
0
 async def screenshot(
     self,
     timeout: int = None,
     type: Literal["png", "jpeg"] = None,
     path: str = None,
     quality: int = None,
     omitBackground: bool = None,
 ) -> bytes:
     binary = await self._channel.send("screenshot",
                                       locals_to_params(locals()))
     return base64.b64decode(binary)
Esempio n. 14
0
 async def selectOption(
     self,
     selector: str,
     values: ValuesToSelect,
     timeout: int = None,
     noWaitAfter: bool = None,
 ) -> List[str]:
     params = locals_to_params(locals())
     if "values" not in params:
         params["values"] = None
     return await self._main_frame.selectOption(**params)
 async def waitForNavigation(
         self,
         timeout: int = None,
         waitUntil: DocumentLoadState = None,
         url: str = None,  # TODO: add url, callback
 ) -> Optional[Response]:
     return cast(
         Optional[Response],
         from_nullable_channel(await self._channel.send(
             "waitForNavigation", locals_to_params(locals()))),
     )
Esempio n. 16
0
 async def waitForFunction(
     self,
     expression: str,
     arg: Any = None,
     force_expr: bool = False,
     timeout: int = None,
     polling: Union[int, Literal["raf"]] = None,
 ) -> JSHandle:
     if not is_function_body(expression):
         force_expr = True
     return await self._main_frame.waitForFunction(**locals_to_params(locals()))
Esempio n. 17
0
 async def dblclick(
     self,
     selector: str,
     modifiers: List[KeyboardModifier] = None,
     position: Dict = None,
     delay: int = None,
     button: MouseButton = None,
     timeout: int = None,
     force: bool = None,
 ) -> None:
     return await self._main_frame.dblclick(**locals_to_params(locals()))
Esempio n. 18
0
 async def addStyleTag(self,
                       url: str = None,
                       path: Union[str, Path] = None,
                       content: str = None) -> ElementHandle:
     params = locals_to_params(locals())
     if path:
         with open(path, "r") as file:
             params["content"] = (file.read() + "\n/*# sourceURL=" +
                                  str(Path(path)) + "*/")
             del params["path"]
     return from_channel(await self._channel.send("addStyleTag", params))
Esempio n. 19
0
 async def dblclick(
     self,
     selector: str,
     modifiers: List[KeyboardModifier] = None,
     position: MousePosition = None,
     delay: int = None,
     button: MouseButton = None,
     timeout: int = None,
     force: bool = None,
 ) -> None:
     await self._channel.send("dblclick", locals_to_params(locals()))
Esempio n. 20
0
 async def selectOption(
     self,
     selector: str,
     values: ValuesToSelect,
     timeout: int = None,
     noWaitAfter: bool = None,
 ) -> List[str]:
     params = locals_to_params(locals())
     if "values" in params:
         values = params.pop("values")
         params = dict(**params, **convert_select_option_values(values))
     return await self._channel.send("selectOption", params)
Esempio n. 21
0
 async def launchPersistentContext(
     self,
     userDataDir: Union[str, Path],
     executablePath: Union[str, Path] = None,
     args: List[str] = None,
     ignoreDefaultArgs: Union[bool, List[str]] = None,
     handleSIGINT: bool = None,
     handleSIGTERM: bool = None,
     handleSIGHUP: bool = None,
     timeout: int = None,
     env: Env = None,
     headless: bool = None,
     devtools: bool = None,
     proxy: ProxyServer = None,
     downloadsPath: Union[str, Path] = None,
     slowMo: int = None,
     viewport: IntSize = None,
     ignoreHTTPSErrors: bool = None,
     javaScriptEnabled: bool = None,
     bypassCSP: bool = None,
     userAgent: str = None,
     locale: str = None,
     timezoneId: str = None,
     geolocation: Geolocation = None,
     permissions: List[str] = None,
     extraHTTPHeaders: Dict[str, str] = None,
     offline: bool = None,
     httpCredentials: Credentials = None,
     deviceScaleFactor: int = None,
     isMobile: bool = None,
     hasTouch: bool = None,
     colorScheme: ColorScheme = None,
     acceptDownloads: bool = None,
     chromiumSandbox: bool = None,
     videosPath: str = None,
     videoSize: IntSize = None,
     recordHar: RecordHarOptions = None,
 ) -> BrowserContext:
     userDataDir = str(Path(userDataDir))
     params = locals_to_params(locals())
     if extraHTTPHeaders:
         params["extraHTTPHeaders"] = serialize_headers(extraHTTPHeaders)
     normalize_launch_params(params)
     try:
         context = from_channel(await self._channel.send(
             "launchPersistentContext", params))
         context._options = params
         return context
     except Exception as e:
         if f"{self.name}-" in str(e):
             raise not_installed_error(
                 f'"{self.name}" browser was not found.')
         raise e
Esempio n. 22
0
 async def click(
     self,
     modifiers: List[KeyboardModifier] = None,
     position: MousePosition = None,
     delay: int = None,
     button: MouseButton = None,
     clickCount: int = None,
     timeout: int = None,
     force: bool = None,
     noWaitAfter: bool = None,
 ) -> None:
     await self._channel.send("click", locals_to_params(locals()))
Esempio n. 23
0
 async def goto(
     self,
     url: str,
     timeout: int = None,
     waitUntil: DocumentLoadState = None,
     referer: str = None,
 ) -> Optional[Response]:
     return cast(
         Optional[Response],
         from_nullable_channel(await self._channel.send(
             "goto", locals_to_params(locals()))),
     )
 async def click(
     self,
     selector: str,
     modifiers: KeyboardModifier = None,
     position: Dict = None,
     delay: int = None,
     button: MouseButton = None,
     clickCount: int = None,
     timeout: int = None,
     force: bool = None,
     noWaitAfter: bool = None,
 ) -> None:
     return await self._main_frame.click(**locals_to_params(locals()))
Esempio n. 25
0
 async def addScriptTag(
     self,
     url: str = None,
     path: str = None,
     content: str = None,
     type: str = None,
 ) -> ElementHandle:
     params = locals_to_params(locals())
     if path:
         with open(path, "r") as file:
             params["content"] = file.read() + "\n//# sourceURL=" + path
             del params["path"]
     return from_channel(await self._channel.send("addScriptTag", params))
Esempio n. 26
0
 async def waitForFunction(
     self,
     expression: str,
     arg: Serializable = None,
     force_expr: bool = None,
     timeout: int = None,
     polling: Union[int, Literal["raf"]] = None,
 ) -> JSHandle:
     if not is_function_body(expression):
         force_expr = True
     params = locals_to_params(locals())
     params["isFunction"] = not (force_expr)
     params["arg"] = serialize_argument(arg)
     return from_channel(await self._channel.send("waitForFunction", params))
Esempio n. 27
0
    async def newContext(
        self,
        viewport: Union[IntSize, Literal[0]] = None,
        ignoreHTTPSErrors: bool = None,
        javaScriptEnabled: bool = None,
        bypassCSP: bool = None,
        userAgent: str = None,
        locale: str = None,
        timezoneId: str = None,
        geolocation: Geolocation = None,
        permissions: List[str] = None,
        extraHTTPHeaders: Dict[str, str] = None,
        offline: bool = None,
        httpCredentials: Credentials = None,
        deviceScaleFactor: int = None,
        isMobile: bool = None,
        hasTouch: bool = None,
        colorScheme: ColorScheme = None,
        acceptDownloads: bool = None,
        defaultBrowserType: str = None,
        proxy: ProxyServer = None,
        videosPath: str = None,
        videoSize: IntSize = None,
        recordHar: RecordHarOptions = None,
        recordVideo: RecordVideoOptions = None,
        storageState: SetStorageState = None,
    ) -> BrowserContext:
        params = locals_to_params(locals())
        # Python is strict in which variables gets passed to methods. We get this
        # value from the device descriptors, thats why we have to strip it out.
        if "defaultBrowserType" in params:
            del params["defaultBrowserType"]
        if viewport == 0:
            del params["viewport"]
            params["noDefaultViewport"] = True
        if extraHTTPHeaders:
            params["extraHTTPHeaders"] = serialize_headers(extraHTTPHeaders)
        if not recordVideo and videosPath:
            params["recordVideo"] = {"dir": videosPath}
            if videoSize:
                params["recordVideo"]["size"] = videoSize

        channel = await self._channel.send("newContext", params)
        context = from_channel(channel)
        self._contexts.append(context)
        context._browser = self
        context._options = params
        return context
Esempio n. 28
0
 async def screenshot(
     self,
     timeout: int = None,
     type: Literal["png", "jpeg"] = None,
     path: Union[str, Path] = None,
     quality: int = None,
     omitBackground: bool = None,
 ) -> bytes:
     params = locals_to_params(locals())
     if "path" in params:
         del params["path"]
     encoded_binary = await self._channel.send("screenshot", params)
     decoded_binary = base64.b64decode(encoded_binary)
     if path:
         with open(path, "wb") as fd:
             fd.write(decoded_binary)
     return decoded_binary
 async def pdf(
     self,
     scale: int = None,
     displayHeaderFooter: bool = None,
     headerTemplate: str = None,
     footerTemplate: str = None,
     printBackground: bool = None,
     landscape: bool = None,
     pageRanges: str = None,
     format: str = None,
     width: Union[str, float] = None,
     height: Union[str, float] = None,
     preferCSSPageSize: bool = None,
     margin: Dict = None,
     path: str = None,
 ) -> bytes:
     binary = await self._channel.send("pdf", locals_to_params(locals()))
     return base64.b64decode(binary)
Esempio n. 30
0
 async def launchPersistentContext(
     self,
     userDataDir: str,
     executablePath: str = None,
     args: List[str] = None,
     ignoreDefaultArgs: List[str] = None,
     handleSIGINT: bool = None,
     handleSIGTERM: bool = None,
     handleSIGHUP: bool = None,
     timeout: int = None,
     env: Dict = None,
     headless: bool = None,
     devtools: bool = None,
     proxy: Dict = None,
     downloadsPath: str = None,
     slowMo: int = None,
     viewport: Dict = None,
     ignoreHTTPSErrors: bool = None,
     javaScriptEnabled: bool = None,
     bypassCSP: bool = None,
     userAgent: str = None,
     locale: str = None,
     timezoneId: str = None,
     geolocation: Dict = None,
     permissions: List[str] = None,
     extraHTTPHeaders: Dict[str, str] = None,
     offline: bool = None,
     httpCredentials: Dict = None,
     deviceScaleFactor: int = None,
     isMobile: bool = None,
     hasTouch: bool = None,
     colorScheme: ColorScheme = None,
     acceptDownloads: bool = None,
 ) -> BrowserContext:
     try:
         return from_channel(
             await self._channel.send(
                 "launchPersistentContext", locals_to_params(locals())
             )
         )
     except Exception as e:
         if f"{self.name}-" in str(e):
             raise not_installed_error(f'"{self.name}" browser was not found.')
         raise e