mokr.execution.context
Attributes
Classes
Class to handle execution of JavaScript functions, element manipulation, |
Module Contents
- mokr.execution.context.LOGGER
- mokr.execution.context.EVALUATION_SCRIPT_URL = '__mokr_evaluation_script__'
- mokr.execution.context.SOURCE_URL_REGEX
- class mokr.execution.context.ExecutionContext(client: mokr.connection.DevtoolsConnection, context_payload: dict, object_handle_factory: Any, frame: mokr.frame.Frame = None)
Class to handle execution of JavaScript functions, element manipulation, and associated runtime error translation.
- Parameters:
client (DevtoolsConnection) – Remote connection from parent.
context_payload (dict) – Context from triggering event.
object_handle_factory (Any) – Factory for handling remote objects. Should create
mokr.execution.JavascriptHandlebased objects.frame (Frame, optional) – The
mokr.frame.Framethat spawned this. Defaults to None.
- property frame: mokr.frame.Frame | None
Parent
mokr.frame.Framethat spawned this.
- async evaluate(page_function: str, *args: Any, force_expr: bool = False) Any
Run
ExecutionContext.evaluate_handleand try to runmokr.execution.JavascriptHandle.jsonon the result to return the object as a dictionary.- Parameters:
page_function (str) – JavaScript function to run.
force_expr (bool) – If True, treat
page_functionas an expression. Otherwise, automatically determine if it is a function or an expression. Defaults to False.
- Raises:
either evaluating the function or requesting the resulting object. –
- Returns:
- The decoded object (dict) via
mokr.execution.JavascriptHandle.jsonor None if a known error occurs decoding it.
- Return type:
dict | None
- async evaluate_handle(page_function: str, *args: Any, force_expr: bool = False, eval_script_url_suffix: str | None = None) mokr.execution.handle.javascript.JavascriptHandle
Execute a JavaScript function with given arguments.
- Parameters:
page_function (str) – JavaScript function to run.
- Raises:
ElementHandleError – Raised if execution fails.
- Returns:
mokr.execution.JavascriptHandle.- Return type:
- async query_objects(javascript_handle: mokr.execution.handle.javascript.JavascriptHandle) mokr.execution.handle.javascript.JavascriptHandle
Query all objects with the given
mokr.execution.JavascriptHandle’sget_property("objectId").- Parameters:
javascript_handle (JavascriptHandle) – A valid (not disposed)
mokr.execution.JavascriptHandleobject.- Raises:
ElementHandleError – Raised if the given handle is disposed, or does not have an “objectId” remote property (primitive type).
- Returns:
- A
mokr.execution.JavascriptHandleinitialised from the remot response.
- A
- Return type: