models module

class ViewPort(*, width: int = 800, height: int = 600, deviceScaleFactor: float = 1.0, isMobile: bool = False, hasTouch: bool = False, isLandscape: bool = False)[source]

Bases: pydantic.main.BaseModel

Keep the consistency of each page’s viewport in a browser instance.

One of the most important use is as the standard setting model for Options.defaultViewport.

width: int

Page width in pixels. Defaults to 800.

height: int

Page height in pixels. Defaults to 600.

deviceScaleFactor: float

Specify device scale factor (can be thought of as dpr). Defaults to 1.0.

isMobile: bool

Whether the meta viewport tag is taken into account. Defaults to False.

hasTouch: bool

Specifies if viewport supports touch events. Defaults to False.

isLandscape: bool

Specifies if viewport is in landscape mode. Defaults to False.

class Options(*, args: List[str] = [], autoClose: bool = True, defaultViewport: models.ViewPort = ViewPort(width=800, height=600, deviceScaleFactor=1.0, isMobile=False, hasTouch=False, isLandscape=False), devtools: bool = False, dumpio: bool = False, env: dict = None, executablePath: str = None, handleSIGINT: bool = True, handleSIGTERM: bool = True, handleSIGHUP: bool = True, headless: bool = False, ignoreHTTPSErrors: bool = True, ignoreDefaultArgs: Union[bool, List[str]] = False, logLevel: Optional[Union[int, str]] = None, slowMo: float = 0.0, userDataDir: str = None)[source]

Bases: pydantic.main.BaseModel

The standard setting model for pyppeteer launcher.

args: List[str]

Additional arguments to pass to the browser instance. The list of Chromium flags can be found here. Defaults to list().

autoClose: bool

Automatically close browser process when script completed. Defaults to True.

defaultViewport: Optional[models.ViewPort]

Set a consistent viewport for each page. Defaults to a default ViewPort instance. None means disables the default viewport.

devtools: bool

Whether to auto-open a DevTools panel for each tab. If this option is True, the headless option will be set False. Defaults to False.

dumpio: bool

Whether to pipe the browser process stdout and stderr into process.stdout and process.stderr. Defaults to False.

env: Optional[dict]

Specify environment variables that will be visible to the browser. None means that same as python process. Defaults to None.

executablePath: Optional[str]

Path to a Chromium or Chrome executable. None means use the default bundled Chromium. Defaults to None.

handleSIGINT: bool

Close the browser process on Ctrl-C. Defaults to True.

handleSIGTERM: bool

Close the browser process on SIGTERM. Defaults to True.

handleSIGHUP: bool

Close the browser process on SIGHUP. Defaults to True.

headless: bool

Whether to run browser in headless mode. Defaults to False.

ignoreHTTPSErrors: bool

Whether to ignore HTTPS errors. Defaults to True.

ignoreDefaultArgs: Union[bool, List[str]]

If True, then do not use pyppeteer’s default args. If a list is given, then filter out the given default args. Dangerous option; use with care. Defaults to False.

logLevel: Optional[Union[int, str]]

Log level to print logs. None means that same as the root logger. Defaults to None.

slowMo: float

Slow down operations by the specified amount of milliseconds. useful so that you can see what is going on. Defaults to 0.0.

userDataDir: Optional[str]

Path to a User Data Directory. Defaults to None.

class Config[source]

Bases: object

Control the behaviours of pydantic model.

arbitrary_types_allowed = True

whether to allow arbitrary user types for fields (they are validated simply by checking if the value is an instance of the type). If False, RuntimeError will be raised on model declaration.

classmethod validate_executable_path(path: Optional[str]) → Optional[str][source]

Validate that the specified executablePath must point to an executable.

Parameters

path (str) – path string.

Returns

path string.

Raises

PathNotAExecutableError – if path does not point to a executable file.

class Browser(*, pyppeteer_browser: pyppeteer.browser.Browser)[source]

Bases: pydantic.main.BaseModel

pyppeteer_browser: pyppeteer.browser.Browser

a pyppeteer browser object.

class Config[source]

Bases: object

Control the behaviours of pydantic model.

arbitrary_types_allowed = True

whether to allow arbitrary user types for fields (they are validated simply by checking if the value is an instance of the type). If False, RuntimeError will be raised on model declaration.

async new_page()models.Page[source]

Make new page on this browser and return its object.

Returns

a Page object.

class Page(*, pyppeteer_page: pyppeteer.page.Page)[source]

Bases: pydantic.main.BaseModel

pyppeteer_page: pyppeteer.page.Page

a pyppeteer page object.

class Config[source]

Bases: object

Control the behaviours of pydantic model.

arbitrary_types_allowed = True

whether to allow arbitrary user types for fields (they are validated simply by checking if the value is an instance of the type). If False, RuntimeError will be raised on model declaration.

async query_locator(locator: str) → Optional[ElementHandle][source]

Get the element which match locator.

If no element matches the locator, return None.

Parameters

locator (str) – a selector or xpath string

Returns

an element handle or None.

async waitfor(locator: str, visible: bool = True, hidden: bool = False, timeout: int = 30000)None[source]

Wait until element which matches locator.

Parameters
  • locator (str) – a selector or xpath string.

  • visible (bool) – Wait for element to be present in DOM and to be visible; i.e. to not have display: none or visibility: hidden CSS properties. Defaults to True.

  • hidden (bool) – Wait for element to not be found in the DOM or to be hidden, i.e. have display: none or visibility: hidden CSS properties. Defaults to False.

  • timeout (int) – Maximum time to wait for in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

Returns

None

Raises

ElementTimeoutError – Timeout exceeded while wait for locator.

async type(locator: str, text: str, delay: int = 0, clear: bool = False)[source]

Focus the element which matches locator and then type text.

Parameters
  • locator – a selector or xpath string.

  • text – what you want to type into.

  • delay (int) – specifies time to wait between key presses in milliseconds. Defaults to 0.

  • clear (bool) – whether to clear existing content befor typing. Defaults to False.

Returns

async click(locator: str, button: Literal[left, middle, right] = 'left', click_count: int = 1, delay: int = 0)[source]

Click the center of the element which matches locator.

Parameters
  • locator (str) – a selector or xpath string.

  • "middle", "right"] button (Literal["left",) – left, right, of middle. Defaults to left.

  • click_count (int) – Defaults to 1.

  • delay (int) – Time to wait between mousedown and mouseup in milliseconds. Defaults to 0.

Returns

None

Raises

ElementNotExistError – if the element which matches locator is not found.

async get_value(locator: str)str[source]

Get the element value or innerText which matches locator.

Parameters

locator (str) – a selector or xpath string.

Returns

the element value or innerText string.

Raises

ElementNotExistError – if the element which matches locator is not found.