Module core.base_driver
Functions
def js_wrap_function_call(fn: str)
Classes
class BaseDriver (url: str | None, init_function: Callable[[], Any] | None)-
Helper class that provides a standard way to create an ABC using inheritance.
Init the driver with the init funtion, and then go to the desired url
Ancestors
- abc.ABC
Methods
def back(self) ‑> None-
Navigate back
def check_visibility(self, xpath: str) ‑> booldef code_for_back(self) ‑> None-
Return driver specific code for going back
def code_for_execute_script(self, js_code: str)-
return driver specific code to execute js script in DOM
def code_for_get(self, url: str) ‑> str-
Return the code to navigate to the url
def code_for_init(self) ‑> str-
Extract the code to past to the begining of the final script from the init code
def default_init_code(self) ‑> Any-
Init the driver, with the imports, since it will be pasted to the beginning of the output
def destroy(self) ‑> None-
Cleanly destroy the underlying driver
def exec_code(self,
code: str,
globals: dict[str, typing.Any] = None,
locals: Mapping[str, object] = None)-
Exec generated code
def execute_script(self, js_code: str) ‑> Any-
Exec js script in DOM
def get(self, url: str) ‑> None-
Navigate to the url
def get_capability(self) ‑> str-
Prompt to explain the llm which style of code he should output and which variables and imports he should expect
def get_current_screenshot_folder(self) ‑> pathlib.Pathdef get_driver(self) ‑> Any-
Return the expected variable name and the driver object
def get_highlighted_element(self, generated_code: str)-
Return the page elements that generated code interact with
def get_html(self, clean: bool = True) ‑> str-
Returns the HTML of the current page. If clean is True, We remove unnecessary tags and attributes from the HTML. Clean HTMLs are easier to process for the LLM.
def get_nodes(self, xpaths: List[str]) ‑> List[DOMNode]def get_nodes_from_html(self, html: str) ‑> List[DOMNode]def get_obs(self) ‑> dict-
Get the current observation of the driver
def get_possible_interactions(self, in_viewport=True, foreground_only=True) ‑> Dict[str, Set[InteractionType]]-
Get elements that can be interacted with as a dictionary mapped by xpath
def get_screenshot_as_png(self) ‑> bytesdef get_screenshots_whole_page(self, max_screenshots=30) ‑> list[str]-
Take screenshots of the whole page
def get_tabs(self) ‑> str-
Return description of the tabs opened with the current tab being focused.
Example of output: Tabs opened: 0 - Overview - OpenAI API 1 - [CURRENT] Nos destinations Train - SNCF Connect
def get_url(self) ‑> str | None-
Get the url of the current page
def highlight_interactive_nodes(self,
*with_interactions: tuple[InteractionType],
color: str = 'red',
in_viewport=True,
foreground_only=True,
label=False)def highlight_node_from_xpath(self, xpath: str, color: str = 'red', label=False) ‑> Callabledef highlight_nodes(self, xpaths: List[str], color: str = 'red', label=False) ‑> Callabledef highlight_nodes_from_html(self, html: str, color: str = 'blue', label=False) ‑> Callabledef is_bottom_of_page(self) ‑> booldef maximize_window(self) ‑> Nonedef remove_highlight(self)def resize_driver(driver, width, height)-
Resize the driver to a targeted height and width.
def resolve_xpath(self, xpath)-
Return the element for the corresponding xpath, the underlying driver may switch iframe if necessary
def save_screenshot(self, current_screenshot_folder: pathlib.Path) ‑> str-
Save the screenshot data to a file and return the path. If the screenshot already exists, return the path. If not save it to the folder.
def scroll_down(self)def scroll_up(self)def switch_default_frame(self) ‑> None-
Switch back to the default frame
def switch_frame(self, xpath) ‑> None-
switch to the frame pointed at by the xpath
def switch_parent_frame(self) ‑> None-
Switch back to the parent frame
def switch_tab(self, tab_id: int) ‑> None-
Switch to the tab with the given id
def wait(self, duration)def wait_for_idle(self)
class DOMNode-
Helper class that provides a standard way to create an ABC using inheritance.
Ancestors
- abc.ABC
Methods
def clear(self)def get_html(self) ‑> strdef highlight(self, color: str = 'red', bounding_box=True)def take_screenshot(self) ‑>
class InteractionType (value, names=None, *, module=None, qualname=None, type=None, start=1)-
An enumeration.
Ancestors
- enum.Enum
Class variables
var CLICKvar HOVERvar SCROLLvar TYPE
class ScrollDirection (value, names=None, *, module=None, qualname=None, type=None, start=1)-
Enum for the different scroll directions. Value is (x, y, dimension_index)
Ancestors
- enum.Enum
Class variables
var DOWNvar LEFTvar RIGHTvar UP
Static methods
def from_string(name: str) ‑> ScrollDirection
Methods
def get_page_script(self, scroll_factor: float = 0.75) ‑> strdef get_script_element_is_scrollable(self) ‑> strdef get_script_page_is_scrollable(self) ‑> strdef get_scroll_xy(self, dimension: List[float], scroll_factor: float = 0.75) ‑> Tuple[int, int]