click_and_upload

def click_and_upload(
    self,
    element_description: str,
    file_path_or_provider: Union(str, callable)
) -> bool:
element_description
string
required

Description of the element to click on the page that opens the operating system’s file upload dialog (e.g., “Upload button”, “Choose file button”).

file_path_or_provider
Union[str, callable]
required

The path to the file you want to upload or a callable that returns a file-like object.

return
bool

Whether the file was uploaded successfully.

raises
ValueError

Raises ValueError if the API request fails or if the API key is not set.

Sample Usage

Let’s say you have a file called simplex-logo.svg in the current directory. You can upload it with a file path:

from simplex import Simplex

simplex = Simplex(api_key="your_api_key")
simplex.create_session()
simplex.goto("https://www.simplex.sh/upload-example.html")
simplex.click_and_upload("Click or drag and drop", "simplex-logo.svg")

or with a callable:

import os
from simplex import Simplex

simplex = Simplex(api_key="your_api_key")
simplex.create_session()
simplex.goto("https://www.simplex.sh/upload-example.html")

def get_file_from_disk():
    return open("simplex-logo.svg", 'rb')

simplex.click_and_upload(
    "Click or drag and drop",
    lambda: get_file_from_disk()
)

click_and_download

def click_and_download(
    self,
    element_description: str,
) -> Tuple[str, bytes]:
element_description
string
required

Description of the element to click on the page that downloads a file in a typical browser setting.

return
Tuple[str, bytes]

The filename and the bytes of the file.

raises
ValueError

Raises ValueError if the API request fails or if the API key is not set.

Sample Usage

You can download a file by clicking on an element that starts a file download.

from simplex import Simplex

simplex = Simplex(api_key="your_api_key")
simplex.create_session()
simplex.goto("https://www.simplex.sh/upload-example.html")
simplex.click_and_upload("Click or drag and drop", "simplex-logo.svg")

or with a callable:

import os
from simplex import Simplex

simplex = Simplex(api_key="your_api_key")
simplex.create_session()
simplex.goto("https://www.simplex.sh/upload-example.html")

def get_file_from_disk():
    return open("simplex-logo.svg", 'rb')

simplex.click_and_upload(
    "Click or drag and drop",
    lambda: get_file_from_disk()
)