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.BaseModelKeep 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.
-
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: Union[str, Path] = 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.BaseModelThe 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().
-
defaultViewport: Optional[ViewPort]¶ Set a consistent viewport for each page. Defaults to a default
ViewPortinstance.Nonemeans disables the default viewport.
-
devtools: bool¶ Whether to auto-open a DevTools panel for each tab. If this option is
True, theheadlessoption will be setFalse. Defaults toFalse.
-
dumpio: bool¶ Whether to pipe the browser process stdout and stderr into
process.stdoutandprocess.stderr. Defaults toFalse.
-
env: Optional[dict]¶ Specify environment variables that will be visible to the browser.
Nonemeans that same as python process. Defaults toNone.
-
executablePath: Union[str, Path]¶ Path to a Chromium or Chrome executable.
Nonemeans use the default bundled Chromium. Defaults toNone.
-
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 toFalse.
-
logLevel: Optional[Union[int, str]]¶ Log level to print logs.
Nonemeans that same as the root logger. Defaults toNone.
-
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
Browser(*, pyppeteer_browser: pyppeteer.browser.Browser)[source]¶ Bases:
pydantic.main.BaseModel-
pyppeteer_browser: pyppeteer.browser.Browser¶ a pyppeteer browser object.
-
class
Config[source]¶ Bases:
objectControl 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
Pageobject.
-
-
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:
objectControl 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, returnNone.- 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: noneorvisibility: hiddenCSS properties. Defaults toTrue.hidden (bool) – Wait for element to not be found in the DOM or to be hidden, i.e. have
display: noneorvisibility: hiddenCSS properties. Defaults toFalse.timeout (int) – Maximum time to wait for in milliseconds. Defaults to 30000 (30 seconds). Pass
0to 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
locatorand then type text.
-