browser.click#
Functions#
button(xpath, timeout=None)
#
button_if_contains_text(xpath, regex, ignore_case=True, timeout=None)
#
Click button if it contains certain text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xpath | str | XPath of the button element. | required |
regex | str | Regular expression or text to search for. The condition works for both ordinary text (e.g. | required |
ignore_case | bool | Ignore case when searching for text. | True |
timeout | float | None | In seconds. Timeout to wait for element. If | None |
download(xpath, timeout=None, await_download=False, expected_file_name=None, idle_download_timeout=None)
#
Click button and download file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xpath | str | XPath of the download button element. | required |
timeout | float | None | In seconds. Timeout to wait for button element. If | None |
await_download | bool | Set to | False |
expected_file_name | str | None | Expected file name to determine when the download is complete. If | None |
idle_download_timeout | float | None | In seconds. Timeout to wait for file size to not increase, which is constantly renewed as long as the file size increases. If | None |
Download Directory
The download directory is implicitly defined in the download_dir
parameter of BrowserSettings
.
Avoid that multiple browser instances have access to the same download directory. As Browserist monitors the download directory for file changes, it may cause unexpected behaviour if multiple files are downloaded to the same directory at the same time.
Example
Examples in context:
Download file in background without waiting. If the browser closes during a download, the download may be aborted or left incomplete:
Download file and wait for download to complete. This will attempt to guess the file name, which may be slower:
Download expected file name and wait for download to complete. It's faster if you know the file name:
download_and_get_file_path(xpath, timeout=None, idle_download_timeout=None)
#
Click button to download file and get file path once download is complete. As downloads are automatically handled by the browser, this is useful if you don't know the file name beforehand.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xpath | str | XPath of the download button element. | required |
timeout | float | None | In seconds. Timeout to wait for button element. If | None |
idle_download_timeout | float | None | In seconds. Timeout to wait for file size to not increase, which is constantly renewed as long as the file size increases. If | None |
Returns:
Type | Description |
---|---|
Path | Path to the downloaded file. Return type is the standard library |
Download Directory
The download directory is implicitly defined in the download_dir
parameter of BrowserSettings
.
Avoid that multiple browser instances have access to the same download directory. As Browserist monitors the download directory for file changes, it may cause unexpected behaviour if multiple files are downloaded to the same directory at the same time.
Example
The return type is Path
from the standard pathlib
library, and so you can easily get the file name or absolute path.
For instance, this will output the file name file.zip
in the terminal:
And this will output the absolute file path /home/user/downloads/file.zip
in the terminal: