sphinx_pyppeteer_builder/typings/pyppeteer/element_handle.pyi

233 lines
8 KiB
Python
Raw Normal View History

2023-09-19 02:01:13 +02:00
"""
This type stub file was generated by pyright.
"""
from typing import Any, Dict, List, Optional, TYPE_CHECKING
from pyppeteer.connection import CDPSession
from pyppeteer.execution_context import ExecutionContext, JSHandle
from pyppeteer.frame_manager import Frame, FrameManager
"""Element handle module."""
if TYPE_CHECKING:
...
logger = ...
class ElementHandle(JSHandle):
"""ElementHandle class.
This class represents an in-page DOM element. ElementHandle can be created
by the :meth:`pyppeteer.page.Page.querySelector` method.
ElementHandle prevents DOM element from garbage collection unless the
handle is disposed. ElementHandles are automatically disposed when their
origin frame gets navigated.
ElementHandle isinstance can be used as arguments in
:meth:`pyppeteer.page.Page.querySelectorEval` and
:meth:`pyppeteer.page.Page.evaluate` methods.
"""
def __init__(self, context: ExecutionContext, client: CDPSession, remoteObject: dict, page: Any, frameManager: FrameManager) -> None:
...
def asElement(self) -> ElementHandle:
"""Return this ElementHandle."""
...
async def contentFrame(self) -> Optional[Frame]:
"""Return the content frame for the element handle.
Return ``None`` if this handle is not referencing iframe.
"""
...
async def hover(self) -> None:
"""Move mouse over to center of this element.
If needed, this method scrolls element into view. If this element is
detached from DOM tree, the method raises an ``ElementHandleError``.
"""
...
async def click(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
"""Click the center of this element.
If needed, this method scrolls element into view. If the element is
detached from DOM, the method raises ``ElementHandleError``.
``options`` can contain the following fields:
* ``button`` (str): ``left``, ``right``, of ``middle``, defaults to
``left``.
* ``clickCount`` (int): Defaults to 1.
* ``delay`` (int|float): Time to wait between ``mousedown`` and
``mouseup`` in milliseconds. Defaults to 0.
"""
...
async def uploadFile(self, *filePaths: str) -> dict:
"""Upload files."""
...
async def tap(self) -> None:
"""Tap the center of this element.
If needed, this method scrolls element into view. If the element is
detached from DOM, the method raises ``ElementHandleError``.
"""
...
async def focus(self) -> None:
"""Focus on this element."""
...
async def type(self, text: str, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
"""Focus the element and then type text.
Details see :meth:`pyppeteer.input.Keyboard.type` method.
"""
...
async def press(self, key: str, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
"""Press ``key`` onto the element.
This method focuses the element, and then uses
:meth:`pyppeteer.input.keyboard.down` and
:meth:`pyppeteer.input.keyboard.up`.
:arg str key: Name of key to press, such as ``ArrowLeft``.
This method accepts the following options:
* ``text`` (str): If specified, generates an input event with this
text.
* ``delay`` (int|float): Time to wait between ``keydown`` and
``keyup``. Defaults to 0.
"""
...
async def boundingBox(self) -> Optional[Dict[str, float]]:
"""Return bounding box of this element.
If the element is not visible, return ``None``.
This method returns dictionary of bounding box, which contains:
* ``x`` (int): The X coordinate of the element in pixels.
* ``y`` (int): The Y coordinate of the element in pixels.
* ``width`` (int): The width of the element in pixels.
* ``height`` (int): The height of the element in pixels.
"""
...
async def boxModel(self) -> Optional[Dict]:
"""Return boxes of element.
Return ``None`` if element is not visible. Boxes are represented as an
list of points; each Point is a dictionary ``{x, y}``. Box points are
sorted clock-wise.
Returned value is a dictionary with the following fields:
* ``content`` (List[Dict]): Content box.
* ``padding`` (List[Dict]): Padding box.
* ``border`` (List[Dict]): Border box.
* ``margin`` (List[Dict]): Margin box.
* ``width`` (int): Element's width.
* ``height`` (int): Element's height.
"""
...
async def screenshot(self, options: Dict[str, Any] = ..., **kwargs: Any) -> bytes:
"""Take a screenshot of this element.
If the element is detached from DOM, this method raises an
``ElementHandleError``.
Available options are same as :meth:`pyppeteer.page.Page.screenshot`.
"""
...
async def querySelector(self, selector: str) -> Optional[ElementHandle]:
"""Return first element which matches ``selector`` under this element.
If no element matches the ``selector``, returns ``None``.
"""
...
async def querySelectorAll(self, selector: str) -> List[ElementHandle]:
"""Return all elements which match ``selector`` under this element.
If no element matches the ``selector``, returns empty list (``[]``).
"""
...
async def querySelectorEval(self, selector: str, pageFunction: str, *args: Any) -> Any:
"""Run ``Page.querySelectorEval`` within the element.
This method runs ``document.querySelector`` within the element and
passes it as the first argument to ``pageFunction``. If there is no
element matching ``selector``, the method raises
``ElementHandleError``.
If ``pageFunction`` returns a promise, then wait for the promise to
resolve and return its value.
``ElementHandle.Jeval`` is a shortcut of this method.
Example:
.. code:: python
tweetHandle = await page.querySelector('.tweet')
assert (await tweetHandle.querySelectorEval('.like', 'node => node.innerText')) == 100
assert (await tweetHandle.Jeval('.retweets', 'node => node.innerText')) == 10
"""
...
async def querySelectorAllEval(self, selector: str, pageFunction: str, *args: Any) -> Any:
"""Run ``Page.querySelectorAllEval`` within the element.
This method runs ``Array.from(document.querySelectorAll)`` within the
element and passes it as the first argument to ``pageFunction``. If
there is no element matching ``selector``, the method raises
``ElementHandleError``.
If ``pageFunction`` returns a promise, then wait for the promise to
resolve and return its value.
Example:
.. code:: html
<div class="feed">
<div class="tweet">Hello!</div>
<div class="tweet">Hi!</div>
</div>
.. code:: python
feedHandle = await page.J('.feed')
assert (await feedHandle.JJeval('.tweet', '(nodes => nodes.map(n => n.innerText))')) == ['Hello!', 'Hi!']
"""
...
J = ...
JJ = ...
Jeval = ...
JJeval = ...
async def xpath(self, expression: str) -> List[ElementHandle]:
"""Evaluate the XPath expression relative to this elementHandle.
If there are no such elements, return an empty list.
:arg str expression: XPath string to be evaluated.
"""
...
Jx = ...
async def isIntersectingViewport(self) -> bool:
"""Return ``True`` if the element is visible in the viewport."""
...