Page
class represents a page in the Dendrite browser instance, it corresponds to a tab in a traditional browser browser. It provides methods for interacting with and manipulating webpages.
Properties
url
Get the current URL of the page. Usagestr
: The current URL.
Methods
goto
Navigates the page to the specified URL, optionally in a new tab. Usageurl
(str): The URL to navigate to.new_page
(bool, optional): Whether to open the URL in a new page. Defaults to False.timeout
(float, optional): The maximum time (in milliseconds) to wait for the page to load. Defaults to 15000.expected_page
(str, optional): A description of the expected page type for verification at runtime. Defaults to an empty string.
- Page: The page object after navigation.
This method exists on the
Page
and Dendrite
class. If invoked from a
Dendrite
instance, it is performed on the active pagenew_tab
Opens a new tab and navigates to the specified URL. Usageurl
(str): The URL to navigate to.timeout
(float, optional): The maximum time (in milliseconds) to wait for the page to load. Defaults to 15000.expected_page
(str, optional): A description of the expected page type for verification at runtime. Defaults to an empty string. Returns
InteractionResponse
: The response from the interaction.
Raises
DendriteException
: If no suitable element is found or if the fill operation fails.
This method exists on the
Page
and Dendrite
class. If invoked from a
Dendrite
instance, it is performed on the active pageclick
Clicks an element on the active page based on the provided prompt. Usageprompt
(str): The prompt describing the element to be clicked.expected_outcome
(str, optional): The expected outcome of the click action.use_cache
(bool, optional): Whether to use cached results for element retrieval. Defaults to True.timeout
(int, optional): The timeout (in milliseconds) for the click operation. Defaults to 15000.force
(bool, optional): Whether to force the click operation. Defaults to False.
InteractionResponse
This method exists on the
Page
and Dendrite
class. If invoked from a
Dendrite
instance, it is performed on the active pagefill
Fills an element on the active page with the provided value based on the given prompt. This method combines the functionality ofget_element
and element.fill
,
allowing for a more concise way to interact with elements on the page.
Usage
prompt
(str): The prompt describing the element to be filled.value
(str): The value to fill the element with.expected_outcome
(str, optional): The expected outcome of the fill action.use_cache
(bool, optional): Whether to use cached results for element retrieval. Defaults to True.max_retries
(int, optional): The maximum number of retry attempts for element retrieval. Defaults to 3.timeout
(int, optional): The timeout (in milliseconds) for the fill operation. Defaults to 15000.
InteractionResponse
: The response from the interaction.
Raises
DendriteException
: If no suitable element is found or if the fill operation fails.
This method exists on the
Page
and Dendrite
class. If invoked from a
Dendrite
instance, it is performed on the active pagefill_fields
Fills multiple fields on the active page with the provided values. This method iterates through the given dictionary of fields and their corresponding values, making a separate fill request for each key-value pair. Usagefields
(Dict[str, Any]): A dictionary where each key is a field identifier (e.g., a prompt or selector) and each value is the content to fill in that field.
Returns
None
This method exists on the
Page
and Dendrite
class. If invoked from a
Dendrite
instance, it is performed on the active pageextract
Extract data from the active page based on a prompt and optional type specification. Usageprompt
(str, optional): The prompt to guide the extraction.type_spec
(TypeSpec, optional): The type specification for the extracted data.use_cache
(bool, optional): Whether to use cached results. Defaults to True.
This method exists on the
Page
and Dendrite
class. If invoked from a
Dendrite
instance, it is performed on the active pageask
Asks a question about the active page and processes the response based on the specified type. Usageprompt
(str): The question or prompt to be asked.type_spec
(TypeSpec, optional): The expected return type, which can be a type or a schema. Defaults to None.
DendriteException
: If the request fails, the exception includes the failure message and a screenshot.
This method exists on the
Page
and Dendrite
class. If invoked from a
Dendrite
instance, it is performed on the active pagewait_for
Waits for the condition specified in the prompt to become true by periodically checking the page content. This method retrieves the page information and evaluates whether the specified condition (provided in the prompt) is met. It continues to retry until the total elapsed time exceeds the timeout. Usageprompt
(str): The prompt to determine the condition to wait for on the page.timeout
(float, optional): The maximum time (in milliseconds) to wait for the condition. Defaults to 30000.
True
if condition is met before timeout.
Raises
PageConditionNotMet
if condition is not met before timeout
This method exists on the
Page
and Dendrite
class. If invoked from a
Dendrite
instance, it is performed on the active pagepress
Presses a keyboard key on the active page, optionally with modifier keys. Usagekey
(str): The main key to be pressed.hold_shift
(bool, optional): Whether to hold the Shift key. Defaults to False.hold_ctrl
(bool, optional): Whether to hold the Control key. Defaults to False.hold_alt
(bool, optional): Whether to hold the Alt key. Defaults to False.hold_cmd
(bool, optional): Whether to hold the Command key (Meta on some systems). Defaults to False.
None
Raises
DendriteException
if key press fails
This method exists on the
Page
and Dendrite
class. If invoked from a
Dendrite
instance, it is performed on the active pageupload_files
Uploads files to the page using the file chooser. Usagefiles
(Union[str, pathlib.Path, FilePayload, Sequence[Union[str, pathlib.Path]], Sequence[FilePayload]]): The file(s) to be uploaded. This can be a file path, aFilePayload
object, or a sequence of file paths orFilePayload
objects.timeout
(float, optional): The maximum amount of time (in milliseconds) to wait for the file chooser to be ready. Defaults to 30000.
None
This method exists on the
Page
and Dendrite
class. If invoked from a
Dendrite
instance, it is performed on the active pageget_download
Retrieves the most recent reference to a downloaded file. To actually save the file to the local machine, you need to invoke thedownload.save_as
method on the object returned from get_download
.
Usage
timeout
(float, optional): The maximum amount of time (in milliseconds) to wait for the download to complete. Defaults to 30000.
Download
This method exists on the
Page
and Dendrite
class. If invoked from a
Dendrite
instance, it is performed on the active pageget_download
Retrieves the downloaded file data. Usagetimeout
(float, optional): The maximum amount of time (in milliseconds) to wait for the download to complete. Defaults to 30000.
- The downloaded file data.
scroll_to_bottom
Scrolls to the bottom of the page continuously until the bottom is reached or a timeout occurs. Usagetimeout
(float, optional): The maximum amount of time (in milliseconds) to continue scrolling. Defaults to 30000.
get_element
Retrieves a single Dendrite element based on the provided prompt. Usageprompt
(str): The prompt describing the element to be retrieved.use_cache
(bool, optional): Whether to use cached results. Defaults to True.max_retries
(int, optional): The maximum number of retry attempts. Defaults to 3.timeout
(int, optional): The timeout (in milliseconds) between retries. Defaults to 3000.
- DendriteElement: The retrieved element.
get_elements
Retrieves Dendrite elements based on either a string prompt or a dictionary of prompts. Usageprompt_or_elements
(Union[str, Dict[str, str]]): The prompt or dictionary of prompts for element retrieval.use_cache
(bool, optional): Whether to use cached results. Defaults to True.max_retries
(int, optional): The maximum number of retry attempts. Defaults to 3.timeout
(int, optional): The timeout (in milliseconds) between retries. Defaults to 3000.context
(str, optional): Additional context for the retrieval. Defaults to an empty string.
- Union[List[DendriteElement], DendriteElementsResponse]: A list of elements or a response object containing the retrieved elements.
upload_files
Uploads files to the page using a file chooser. Usagefiles
(Union[str, pathlib.Path, FilePayload, Sequence[Union[str, pathlib.Path]], Sequence[FilePayload]]): The file(s) to be uploaded.timeout
(float, optional): The maximum amount of time (in milliseconds) to wait for the file chooser to be ready. Defaults to 30000.
get_content
Retrieves the content of the current page. Usagestr
: The HTML content of the current page.