create
create(url, wait=True, timeout=100, chrome_path=None)
Description
Creates a Chrome page object.
Parameters
url<str> The URL to open.
wait<bool> Specifies whether to wait for the page to finish loading.
timeout<int> The maximum wait time in seconds. Default: 100.
chrome_path<str> The path to the chrome.exe file. By default, the system searches in %ProgramFiles% and %ProgramFiles(x86)%.
For information on Chrome incognito mode, see Run in Chrome incognito mode.
Return value
Returns a ChromeTab object.
Example- rpa.app.chrome.create-
# Note: Before using this method, ensure that the Aliyun RPA Chrome extension is installed and enabled.
# The following code provides an example:
page = rpa.app.chrome.create('www.aliyun.com')catch
catch(name, mode='title', pattern='contain', timeout=10)
Description
Captures an already open page.
Parameters
name<str> The title or URL of the page.
mode<str> The property to use for matching the page.
Options:
title: Matches by page title.url: Matches by page URL.
pattern<str> The matching mode.
Options:
equal: Exact match.contain: Contains match.regular: Regular expression match.
timeout<int> The maximum time, in seconds, to wait for the page.
Return value
Returns a ChromeTab object.
Returns the first page that matches the criteria.
Example- rpa.app.chrome.catch-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled, and that the target page is already open before using this method.
# By default, this method performs a contains match on the page title:
page = rpa.app.chrome.catch('Alibaba Cloud')
# Match by title using a regular expression:
page = rpa.app.chrome.catch(".*", mode="title",pattern="regular")
# Match by URL using an exact match:
page = rpa.app.chrome.catch("baidu", mode="url",pattern="equal")
# Match by URL using a 'contains' match:
page = rpa.app.chrome.catch("baidu", mode="url",pattern="contain")
# Match by URL using a regular expression:
page = rpa.app.chrome.catch(".*m/$", mode="url",pattern="regular")catch_specific_pages
catch_specific_pages(name, mode='title', pattern='contain')
Description
Captures all open pages that match the specified criteria.
To capture a single page, use catch.
Parameters
name<str> The title or URL of the page.
mode<str> The property to use for matching the page.
Options:
title: Matches by page title.url: Matches by page URL.
pattern<str> The matching mode.
Options:
equal: Exact match.contain: Contains match.regular: Regular expression match.
Return value
Returns a list of ChromeTab objects.
Example- rpa.app.chrome.catch_specific_pages-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled, and that at least one matching page is open before using this method.
# By default, this method performs a 'contains' match on the page title:
page_list = rpa.app.chrome.catch_specific_pages('Alibaba Cloud')
# Match by title using a regular expression:
page_list = rpa.app.chrome.catch_specific_pages(".*", mode="title",pattern="regular")
# Match by URL using an exact match:
page_list = rpa.app.chrome.catch_specific_pages("baidu", mode="url",pattern="equal")
# Match by URL using a 'contains' match:
page_list = rpa.app.chrome.catch_specific_pages("baidu", mode="url",pattern="contain")
# Match by URL using a regular expression:
page_list = rpa.app.chrome.catch_specific_pages(".*m/$", mode="url",pattern="regular")catch_all_pages
catch_all_pages()
Description
Captures all open Chrome pages.
Example- rpa.app.chrome.catch_all_pages-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# The following code provides an example:
page_list = rpa.app.chrome.catch_all_pages()catch_activated_pages
catch_activated_pages()
Description
Captures all active Chrome pages.
When a new page opens from an existing one:
(Recommended) Use
attrto get the new page's URL (for example, by retrieving thehrefattribute of a control), and then usecreateto open it.If the URL cannot be retrieved (for example, if the page uses JavaScript for navigation), first click the control, then:
Use
catchto capture the new page based on its title or URL. This method waits for the page to load before proceeding.If the new page's title or URL is dynamic and lacks a distinct pattern, use
catch_activated_pagesto capture the active page. You should add atime.sleep()delay to your code to ensure the new page finishes loading.
Example- rpa.app.chrome.catch_activated_pages-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# When you have multiple Chrome browser processes open, each with multiple tabs, this method returns the active tab from each process.
# The following code provides an example:
page_list = rpa.app.chrome.catch_activated_pages()close_all
close_all()
Description
Closes all pages.
Example- rpa.app.chrome.close_all-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# The following code provides an example:
rpa.app.chrome.close_all()maximize
maximize()
Description
Maximizes the browser window.
Example- rpa.app.chrome.maximize-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# If multiple Chrome windows are open, this method maximizes only one of them.
# The following code provides an example:
rpa.app.chrome.maximize()minimize
minimize()
Description
Minimizes the browser window.
Example- rpa.app.chrome.minimize-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# If multiple Chrome windows are open, this method minimizes only one of them.
# The following code provides an example:
rpa.app.chrome.minimize()restore
restore()
Description
Restores the browser window to its previous size and position.
Example- rpa.app.chrome.restore-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# If multiple Chrome windows are open, this method restores only one of them.
# The following code provides an example:
rpa.app.chrome.restore()catch_from_element_name
catch_from_element_name(element)
Description
Captures a page by the name of an element it contains.
Parameters
element<str> The name of the element.
Return value
Returns a ChromeTab object.
Example- rpa.app.chrome.catch_from_element_name-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# The following code provides an example:
page = rpa.app.chrome.catch_from_element_name('Baidu search box')
page.input_text('Baidu search box','Alibaba Cloud')get_cookies
get_cookies(url=None, domain=None, name=None)
Description
Retrieves cookies that match the specified filters.
Parameters
url<str> The URL to filter cookies by. When specified, only cookies from this URL are returned.
domain<str> Filters cookies by domain. This retrieves cookies for the exact domain and its subdomains.
name<str> Filters cookies by name.
Return value
Returns a list of cookie objects.
Example- rpa.app.chrome.get_cookies-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# The url parameter must be a complete URL, including the protocol (e.g., https://).
# The following code provides an example:
cookies = rpa.app.chrome.get_cookies(url='https://www.aliyun.com')remove_cookie
remove_cookie(url, name)
Description
Deletes a cookie.
Parameters
url<str> The URL associated with the cookie.
name<str> The name of the cookie to delete.
Example- rpa.app.chrome.remove_cookie-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# The url parameter must be a complete URL, including the protocol (e.g., https://).
# The following code provides an example:
rpa.app.chrome.remove_cookie('https://www.baidu.com','domain')set_cookie
set_cookie(url, name, domain=None, value=None, path=None, secure=False, http_only=False, expiration_date=None)
Description
Sets a cookie.
Parameters
url<str> The URL to associate with the cookie.
name<str> The name of the cookie.
domain<str> The domain of the cookie. If omitted, the cookie becomes a host-only cookie.
value<str> The value of the cookie. If omitted, it defaults to an empty string.
path<str> The path of the cookie. Defaults to the path portion of the url parameter.
secure<bool> Specifies whether the cookie should be marked as secure.
http_only<bool> Specifies whether the cookie should be marked as HTTP-only.
expiration_date<str> The expiration date of the cookie.
Example- rpa.app.chrome.set_cookie-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# The url parameter must be a complete URL, including the protocol (e.g., https://).
# The following code provides an example:
rpa.app.chrome.set_cookie('https://www.baidu.com','rpa_test',value='Aliyun RPA test_www.aliyun.com')network_capture_stop
network_capture_stop(capture_key)
Description
Stops a network capture session.
Parameters
capture_key<str> The key that identifies the network capture session.
Return value
None.
Example- rpa.app.chrome.network_capture_stop-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# The following code provides an example:
# Open the Alibaba Cloud page in Chrome
page = rpa.app.chrome.create('www.aliyun.com')
# Start network capture
capture_key = page.network_capture_start(url='', use_regular=False, capture_types=[])
# Refresh the page
page.reload()
# Get the network capture result
web_respond_body = rpa.app.chrome.get_network_capture_result(capture_key)
# Stop network capture
rpa.app.chrome.network_capture_stop(capture_key)
# Log the information
rpa.console.logger.info(web_respond_body)get_network_capture_result
get_network_capture_result(capture_key)
Description
Retrieves the result of a network capture session.
Parameters
capture_key<str> The key that identifies the network capture session.
Return value
Returns the network capture results as a JSON string.
Example- rpa.app.chrome.get_network_capture_result-
# Note: Ensure that the Aliyun RPA Chrome extension is installed and enabled before using this method.
# The following code provides an example:
# Open the Alibaba Cloud page in Chrome
page = rpa.app.chrome.create('www.aliyun.com')
# Start network capture
capture_key = page.network_capture_start(url='', use_regular=False, capture_types=[])
# Refresh the page
page.reload()
# Get the network capture result
web_respond_body = rpa.app.chrome.get_network_capture_result(capture_key)
# Stop network capture
rpa.app.chrome.network_capture_stop(capture_key)
# Log the information
rpa.console.logger.info(web_respond_body)