Create
create(url, wait=True, timeout=100, chrome_path=None)
Description
Opens the specified URL in a new Chrome tab.
For Chrome incognito mode, see Running in Chrome Incognito Mode.
Parameters
url<str> The URL to open.
wait<bool> Specifies whether to wait for the page to finish loading.
timeout<int> The wait timeout in seconds. Default: 100.
chrome_path<str> The path to the chrome.exe file.
If set to
None, the application automatically searches in the%ProgramFiles%and%ProgramFiles(x86)%directories.If a path is provided, specify the full path to
chrome.exe, for example,C:\Program Files\Google\Chrome\Application\chrome.exe.
Returns
A ChromeTab object<ChromeTab>.
Example- rpa.app.chrome.create-
# Note: Ensure the Alibaba Cloud RPA chrome extension is installed and enabled before using this method.
# Example:
page = rpa.app.chrome.create('www.aliyun.com')Catch
catch(name, mode='title', pattern='contain', timeout=10)
Description
Captures an already opened page.
Parameters
name<str> The page title or URL.
mode<str> The page matching criterion.
Valid values:
title: Match by page title.url: Match by page URL.
pattern<str> The matching rule.
Valid values:
equal: An exact match.contain: A partial match (matches a substring).regular: Matches using a regular expression.
timeout<int> The timeout in seconds for finding a matching page.
Returns
A ChromeTab object<ChromeTab>.
This method returns the first page that matches the specified conditions.
Example- rpa.app.chrome.catch-
# Note: Ensure the Alibaba Cloud RPA chrome extension is installed and enabled, and that the target webpage is already open.
# By default, this method matches a substring of the page title.
page = rpa.app.chrome.catch('Alibaba Cloud')
# Match by title with a regular expression
page = rpa.app.chrome.catch(".*", mode="title", pattern="regular")
# Match by URL with an exact match
page = rpa.app.chrome.catch("https://www.baidu.com", mode="url", pattern="equal")
# Match by URL with a containment match
page = rpa.app.chrome.catch("baidu", mode="url", pattern="contain")
# Match by URL with 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 pages that match the specified conditions.
To capture a single page, use the catch method.
Parameters
name<str> The page title or URL.
mode<str> The page matching criterion.
Valid values:
title: Match by page title.url: Match by page URL.
pattern<str> The matching rule.
Valid values:
equal: An exact match.contain: A partial match (matches a substring).regular: Matches using a regular expression.
Returns
A list of ChromeTab objects<list>.
Example- rpa.app.chrome.catch_specific_pages-
# Note: Ensure the Alibaba Cloud RPA chrome extension is installed and enabled, and that at least one matching webpage is open.
# By default, this method matches a substring of the page title.
page_list = rpa.app.chrome.catch_specific_pages('Alibaba Cloud')
# Match by title with a regular expression
page_list = rpa.app.chrome.catch_specific_pages(".*", mode="title", pattern="regular")
# Match by URL with an exact match
page_list = rpa.app.chrome.catch_specific_pages("https://www.baidu.com", mode="url", pattern="equal")
# Match by URL with a containment match
page_list = rpa.app.chrome.catch_specific_pages("baidu", mode="url", pattern="contain")
# Match by URL with a regular expression
page_list = rpa.app.chrome.catch_specific_pages(".*m/$", mode="url", pattern="regular")Catch all pages
catch_all_pages()
Description
Gets all open pages.
Example- rpa.app.chrome.catch_all_pages-
# Note: Ensure the Alibaba Cloud RPA chrome extension is installed and enabled.
# Example:
page_list = rpa.app.chrome.catch_all_pages()Catch activated pages
catch_activated_pages()
Description
Gets all active pages.
Use case: Getting a new page that opens from an existing page.
(Recommended) Method 1: Use the attr method to get the pop-up URL (for example, by getting the
hrefattribute of a control), and then use the create method to open the new page.Method 2: If you cannot get the URL (for example, if the page uses JavaScript for redirection), click the control and then perform one of the following actions:
Recommended: Use catch to get the new page based on its title or URL characteristics. This ensures the page has finished loading and is ready for subsequent operations.
If the new page's title or URL is dynamic and has no stable characteristics, use
catch_activated_pagesto get the currently active page. Addtime.sleep()to your code to ensure the new page has finished loading.
Example- rpa.app.chrome.catch_activated_pages-
# Note: Ensure the Alibaba Cloud RPA chrome extension is installed and enabled.
# If you have multiple Chrome browser processes open, each with multiple tabs, this method returns the active tab from each process.
# 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 the Alibaba Cloud RPA chrome extension is installed and enabled.
# Example:
rpa.app.chrome.close_all()Maximize
maximize()
Description
Maximizes the browser window.
Example- rpa.app.chrome.maximize-
# Note: Ensure the Alibaba Cloud RPA chrome extension is installed and enabled.
# If multiple Chrome windows are open, this method maximizes only one of them.
# Example:
rpa.app.chrome.maximize()Minimize
minimize()
Description
Minimizes the browser window.
Example- rpa.app.chrome.minimize-
# Note: Ensure the Alibaba Cloud RPA chrome extension is installed and enabled.
# If multiple Chrome windows are open, this method minimizes only one of them.
# 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 the Alibaba Cloud RPA chrome extension is installed and enabled.
# If multiple Chrome windows are open, this method restores only one of them.
# Example:
rpa.app.chrome.restore()Catch from element name
catch_from_element_name(element)
Description
Captures a page by its element name.
Parameters
element<str> The element name.
Returns
A ChromeTab object.
Example- rpa.app.chrome.catch_from_element_name-
# Note: Ensure the Alibaba Cloud RPA chrome extension is installed and enabled.
# 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> Restricts results to cookies that match the specified URL.
domain<str> Restricts results to cookies from the specified domain or its subdomains.
name<str> Filters cookies by name.
Returns
A list of matching cookie objects<list>.
Example- rpa.app.chrome.get_cookies-
# Note: Ensure the Alibaba Cloud RPA chrome extension is installed and enabled.
# The url parameter must be a complete URL, including the protocol (e.g., https://).
# 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 the Alibaba Cloud RPA chrome extension is installed and enabled.
# The url parameter must be a complete URL, including the protocol (e.g., https://).
# 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> Whether to mark the cookie as secure.
http_only<bool> Whether the cookie should be flagged as http_only
expiration_date<str>The expiration date of the cookie.
Sample Call - rpa.app.chrome.set_cookie -
# Note: This method requires that the Chrome extension for Alibaba Cloud RPA is installed and enabled.
# The url parameter must be a complete URL that includes the protocol.
# Usage example:
rpa.app.chrome.set_cookie('https://www.baidu.com','rpa_test',value='Alibaba Cloud RPA Test_www.aliyun.com')network_capture_stop
network_capture_stop(capture_key)
Stops web request monitoring.
Stop web request monitoring
capture_key<str> The key that identifies the web request monitoring session.
Returns
None.
None
Example- rpa.app.chrome.network_capture_stop-
# Note: Make sure that the Chrome extension for Aliyun RPA is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code shows an example.
# Open the Alibaba Cloud page in Google Chrome.
page = rpa.app.chrome.create('www.aliyun.com')
# Start monitoring web requests.
capture_key = page.network_capture_start(url='', use_regular=False, capture_types=[])
# Refresh the page.
page.reload()
# Retrieve the results of web request monitoring.
web_respond_body = rpa.app.chrome.get_network_capture_result(capture_key)
# Stop monitoring web requests.
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)
Gets the result of a web request monitoring session.
Obtain web request monitoring results
capture_key<str> The key that identifies the web request monitoring session.
Returns
A JSON string containing the web request monitoring results<string>.
Example- rpa.app.chrome.get_network_capture_result-
Example- rpa.app.chrome.get_network_capture_result-
# Note: This method requires the Aliyun RPA Chrome extension to be installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following is a code sample:
# Open the Alibaba Cloud page in Google Chrome.
page = rpa.app.chrome.create('www.aliyun.com')
# Start web request monitoring.
capture_key = page.network_capture_start(url='', use_regular=False, capture_types=[])
# Refresh the page.
page.reload()
# Obtain the web request monitoring result.
web_respond_body = rpa.app.chrome.get_network_capture_result(capture_key)
# Stop web request monitoring.
rpa.app.chrome.network_capture_stop(capture_key)
# Record an information log.
rpa.console.logger.info(web_respond_body)