ChromeTab

更新时间:
复制 MD 格式

Close

close()

Method Description

Close the browser

Code sample: rpa.app.chrome.ChromeTab.close

# Notes:
# - Make sure you have installed and enabled the Alibaba Cloud RPA Chrome extension.
# - Call this method on a ChromeTab instance.
# Example:
page = rpa.app.chrome.create('www.aliyun.com')
page.close()

Navigation

navigate(url, wait=True, timeout=100)

Description

Go to the specified URL.

Parameters

url<str>The URL to open.

wait<bool>Pauses the operation until loading is complete.

timeout<int>Timeout in seconds. Default: 100.

Example - rpa.app.chrome.ChromeTab.navigate

# Requires the Alibaba Cloud RPA Chrome extension to be installed and enabled.
# This method must be called on a ChromeTab instance.
# Example:
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
page.navigate('help.aliyun.com/document_detail/175379.html')

Backup

back(wait=True, timeout=100)

Description

browser back button

Parameters

wait<bool>Specifies whether to wait for the page to load completely.

timeout<int>The timeout in seconds. Defaults to 100.

Example - RPA.app.Chrome.ChromeTab.back

# This method requires the Alibaba Cloud RPA Chrome extension to be installed and enabled.
# This method must be called on a ChromeTab instance.
# Example:
url = 'www.baidu.com'
page = rpa.app.chrome.create(url)
page.input_text('Baidu search box','Alibaba Cloud')
page.click('Baidu search button', simulate=True)
page.back()

Forwarding

forward(wait=True, timeout=100)

Description

Navigates forward in the browser history.

Parameters

wait<bool>Determines whether to wait for loading to complete.

timeout<int>The timeout in seconds, defaulting to 100.

Example: rpa.app.chrome.ChromeTab.forward

# Requires the Aliyun RPA Chrome extension to be installed and enabled.
# Call this method on a ChromeTab instance.
# Example:
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
page.navigate('help.aliyun.com/document_detail/175379.html')
page.back()
page.forward()

Activate

activate()

Method Description

Activation page

Example: rpa.app.chrome.ChromeTab.activate

# Requires the Alibaba Cloud RPA Chrome extension to be installed and enabled.
# Call this method on a ChromeTab instance.
# Example:
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
page.activate()

URL

URL()

Description

Returns the current URL.

Return value

Returns the URL.<str>

Example: rpa.app.chrome.ChromeTab.url

# This method requires the Alibaba Cloud RPA Chrome extension to be installed and enabled.
# You must call this method on a ChromeTab instance.
# Example:
page = rpa.app.chrome.create('www.aliyun.com')
url = page.url()

Title

title()

Description

Get the title

Return value

Returns the title<str>

Example: rpa.app.chrome.ChromeTab.title

# To use this method, install and enable the Alibaba Cloud RPA Chrome extension.
# Call this method on a ChromeTab instance.
# Example:
page = rpa.app.chrome.create('www.aliyun.com')
title = page.title()

Reload

reload(bypass_cache=False, wait=True, timeout=100)

Description

Refresh the page.

Parameters

bypass_cache<bool>Specifies whether to bypass the cache.

wait<bool>Whether to wait for the loading to complete.

timeout<int>The timeout in seconds. Default: 100.

Code sample: rpa.app.chrome.ChromeTab.reload

# Requires the Alibaba Cloud RPA Chrome extension to be installed and enabled.
# Call this method on a ChromeTab instance.
# Example:
page = rpa.app.chrome.create('www.aliyun.com')
page.reload()

get_cookie

get_cookie()

Description

Retrieves all cookies for the current website.

Return value

Returns all cookies for the current website<list>

Example: rpa.app.chrome.ChromeTab.get_cookie

# This method requires the Alibaba Cloud RPA Chrome extension to be installed and enabled.
# Call this method on a ChromeTab instance.
# Example:
page = rpa.app.chrome.create('www.aliyun.com')
cookie = page.get_cookie()

network_capture_start

network_capture_start(url='', use_regular=False, capture_types=[])

Description

Enables web request monitoring.

Parameters

url<str>Specifies the url to listen on. Defaults to empty, in which case the service listens on all urls.

use_regular<bool>Whether to use a regular expression to match URLs.

capture_types<list>Specifies the request types to monitor. Supported values: XHR/Fetch, XHR, Fetch, JS, CSS, Image, Font, Document, Websocket, and other.

Return value

The key for a web request listener, used to retrieve the listener's result or stop the listener.<string>

Code sample: rpa.app.chrome.ChromeTab.network_capture_start

# Requires the Aliyun RPA Chrome extension to be installed and enabled.
# Call this method on a ChromeTab instance.
# Example:
# Open the Alibaba Cloud page in Google Chrome.
page = rpa.app.chrome.create('www.aliyun.com')
# Start network capture.
capture_key = page.network_capture_start(url='', use_regular=False, capture_types=[])
# Reload the page.
page.reload()
# Get the network capture result.
web_respond_body = rpa.app.chrome.get_network_capture_result(capture_key)
# Stop the network capture.
rpa.app.chrome.network_capture_stop(capture_key)
# Log the captured response body.
rpa.console.logger.info(web_respond_body)

wait_load_completed

wait_load_completed(timeout=100)

Description

Wait for the page to load.

Parameters

timeout<int>The timeout period in seconds. Default: 100.

Example: rpa.app.chrome.ChromeTab.wait_load_completed

# Requires the Aliyun RPA Chrome extension to be installed and enabled.
# Call this method on a ChromeTab instance object.
# Example:
page = rpa.app.chrome.create('www.aliyun.com')
page.wait_load_completed()

Copy

copy()

Method description

Copy from the current page.

Return value

Returns true if the operation succeeds; otherwise, false (boolean).

Example: rpa.app.chrome.ChromeTab.copy

# Notes:
# 1. You must install and enable the Alibaba Cloud RPA Chrome extension to use this method.
# 2. You must first select the content using another method.
# 3. This method writes the selected content to the system clipboard.
# This example shows how to select text by double-clicking a cell and then copy it:
page = rpa.app.chrome.create('https://help.aliyun.com/document_detail/175379.html')
page.double_click('queryClientViews-chrome')
page.copy()

Paste

paste()

Method description

Paste on the current page.

Return value

A boolean value indicating whether the operation succeeded.<boolean>

Sample call: rpa.app.chrome.ChromeTab.paste

# Notes:
# 1. To use this method, you must install and enable the Aliyun RPA Chrome extension.
# 2. This method only executes the paste command. You must first select the target area.
# 3. This method pastes the content from the clipboard into the selected area.
# The following code sample shows how to copy content from a cell, click a search box, and paste it:
page = rpa.app.chrome.create('https://help.aliyun.com/document_detail/175379.html')
page.double_click('queryClientViews-chrome')
page.copy()
page.click('文档搜索框-chrome')
page.paste()

Cut

cut()

Description

Cut from the current page.

Return value

Indicates whether the operation succeeded.<bool>

Sample code: rpa.app.chrome.ChromeTab.cut

# Notes:
# 1. To use this method, you must install and enable the Aliyun RPA chrome extension.
# 2. This method only performs a cut. You must select the content to cut before calling this method. The method has no effect if the content cannot be cut.
# 3. This method places the cut content on the system clipboard.
# In this example, you manually open the Baidu home page and enter text in the input box.
# The script then double-clicks the input box to select the text and performs the cut:
page = rpa.app.chrome.catch('www.baidu.com',mode='url')
page.double_click('Baidu input box-chrome')
page.cut()

execute_js

execute_js(code, element=None, index=1, timeout=10)

Description

Run the JS code.

Parameters

code<str>The JS code to execute.

element<str> The element in which to execute the JavaScript (for cross-domain scenarios).

index<int>Specifies the index of the control when multiple are found.

timeout<int>The timeout duration.

Return value

Returns the execution result as a JSON string<str>

Code sample: rpa.app.chrome.ChromeTab.execute_js

# Note: To use this method, you must install and enable the Alibaba Cloud RPA Chrome extension.
# This method must be called on a ChromeTab instance.
# Example:
js_code = """
    function test(){ 
    var div1 = document.getElementById("su").getAttribute('%s');
    return(div1) 
    } ; 
result = test() ; 
console.log(result) ; 
alert(result);
return result;
"""%'value'

url = 'www.baidu.com'
page = rpa.app.chrome.create(url)

value = page.execute_js(js_code)
print(value)

Table

table(value, type='index', return_type='text', parent_element=None)

Method description

Get a table

Parameters

type<string>The match type.

Optional:

  • index: Index Matching

  • text: Text Matching

  • html: HTML Matching

return_type<str>The return type.

Optional:

  • text: text type

  • html: html type

Returns

Returns a two-dimensional array or the HTML for the matched table<list>

Code sample: rpa.app.chrome.ChromeTab.table

# Notes:
# 1. Ensure you have installed and enabled the Alibaba Cloud RPA Chrome extension.
# 2. This method retrieves an HTML 

Scroll

scroll(height=0, element=None, index=1, parent_element=None, timeout=10, direction='top')

Description

Scroll the page.

Parameters

height<int>Scrolls by the specified height. If omitted, scrolls to the bottom of the page.

element<str>The control.

index<int>Specifies the index of the control to select when multiple are found.

parent_element<Element>Parent element.

timeout<int>The timeout period.

direction<str>The scrollbar direction.

Optional:

  • left: Scrolls left

  • top: Scrolls down

Example: rpa.app.chrome.ChromeTab.scroll

# Notes:
# 1. To use this method, install and enable the Alibaba Cloud RPA Chrome extension.
# 2. If you omit all parameters or set the height parameter to 0, this method scrolls the page to the bottom.
# Example:
page = rpa.app.chrome.create('https://help.aliyun.com/document_detail/175379.html')
page.scroll()
# To scroll a list pane, pass parameters such as height and element. For example:
page.scroll(height=200, element='scrollable list pane', index=1, parent_element=None, timeout=10, direction='top')
Important

The scroll bar is the control to record.scroll_1

download_by_url

download_by_url(url, path, wait=True, complete_timeout=120)

Method Description

Downloads a file from a URL (as a prerequisite, navigate to chrome://settings/ and disable "Ask where to save each file before downloading").

Parameters

url<str>A link to download the file.

path<str>Path where the file is saved.

complete_timeout<int>The timeout for completion, in seconds.

wait<bool>Whether to wait for completion.

Example: rpa.app.chrome.ChromeTab.download_by_url

# Notes:
# 1. This method requires the Alibaba Cloud RPA Chrome extension.
# Downloads the specified file to the designated path.
url = 'www.cninfo.com.cn'
page = rpa.app.chrome.create(url)
download_url = 'http://www.cninfo.com.cn/new/announcement/download?bulletinId=1209275224&announceTime=2021-02-10'
download_path = r'D:\Alibaba-SW.pdf'
page.download_by_url(download_url,download_path)

get_element_by_name

get_element_by_name(element, index=1, parent_element=None, timeout=10)

Description

Get Object

Parameters

control<str>The UI control.

index<int>The index of the control to select when multiple are found.

parent_element<Element>The parent element.

timeout<int>The timeout period.

Return value

Returns a control object <Element>

Example: rpa.app.chrome.ChromeTab.get_element_by_name

# Notes:
# 1. Ensure you have installed and enabled the Alibaba Cloud RPA Chrome extension.
# 2. Before using this method, use the capture control feature to capture an element from the page.
# Example:
url = 'https://www.baidu.com/'
page = rpa.app.chrome.create(url)
element = page.get_element_by_name('Baidu search button-chrome')
text = element.text()

get_element_by_css

get_element_by_css(css, index=1, parent_element=None, timeout=10)

Description

Get a control using a CSS expression.

Parameter

CSS<str>CSS selector

index<int>If multiple controls match, specify the index of the target control.

parent_element<str>The parent control.

timeout<int>The request timeout.

Return value

Returns an Element object

Code sample: rpa.app.chrome.ChromeTab.get_element_by_css

# Notes:
# 1. Ensure you have installed and enabled the Alibaba Cloud RPA Chrome extension.
# 2. This method locates an element using a standard CSS selector expression.
# Example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
css_selector = "span.lake-fontsize-11" # Selects a  element with the class "lake-fontsize-11".
element = page.get_element_by_css(css_selector)
text = element.text()

Count

count(element, parent_element=None)

Description

Returns the number of controls.

Parameters

element<str>The control.

parent element<str>Parent element.

Sample code: rpa.app.chrome.ChromeTab.count

# Notes:
# 1. To use this method, install and enable the Aliyun RPA Chrome extension.
# 2. This method is typically used to count a group of similar controls.
# Example:
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
element_count = page.count('login button-chrome')

wait_loaded

wait_loaded(element, index=1, parent_element=None, timeout=10, ignore_error=True)

Description

Wait for the control to load.

Parameters

element<str>

index<int>The index of the control to use if more than one is found.

parent_element<str>The parent control object.

timeout<int>The timeout duration.

ignore_error<bool>Whether to ignore errors.

Code example: RPA.app.Chrome.ChromeTab.wait_loaded

# Notes:
# 1. This method requires you to install and enable the Alibaba Cloud RPA Chrome extension.
# 2. Before using this method, ensure the page element has been captured using the capture control.
# Example:
page = rpa.app.chrome.create('www.taobao.com')
flag = page.wait_loaded('Taobao logo')

wait_disappear

wait_disappear(element, index=1, parent_element=None, timeout=10)

Method description

Wait for Control to Disappear

Parameters

control<str>The control.

index<int>The index of the control to use when multiple are found.

parent_element<str>The parent element.

timeout<int>The timeout period.

Code example: rpa.app.chrome.ChromeTab.wait_disappear

# Notes:
# 1. Ensure you have installed and enabled the Alibaba Cloud RPA Chrome extension.
# 2. Before using this method, ensure you have captured the page element using capture control.
# Example:
page = rpa.app.chrome.create('www.taobao.com')
page.wait_disappear('Taobao logo')

handle_javascript_dialog

handle_javascript_dialog(value='ok', text=None)

Description

Handling JavaScript pop-ups

Parameters

value<str>The action to perform on the dialog.

Options:

  • OK: Confirms the action.

  • Cancel: Cancels the action.

text<string>The text to enter in the dialog box.

Example: RPA.app.chrome.ChromeTab.handle_javascript_dialog

# Notes:
# 1. Make sure to install and enable the Alibaba Cloud RPA Chrome extension.
# Example:
page = rpa.app.chrome.catch('W3School TIY Editor', mode='title', pattern='contain')
page.click('Click me to open a pop-up')
page.handle_javascript_dialog()
Note

To create a pop-up:

  1. Open the W3Schools page.

  2. Enter the HTML script in the script box on the left.

  3. Click Run Code. A pop-up button appears on the right.

1695718066756_40BCDD34-2CB3-40ab-A8FE-3A907D64CDB4.png

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script>
function myFunction()
{
    alert("You have triggered a pop-up!");
}
</script>
</head>
<body>

<input type="button" onclick="myFunction()" value="Trigger Pop-up">

</body>
</html>

Click

click(element, index=1, parent_element=None, simulate=True, button='left', offset_x=0, offset_y=0, move_mode="without-track", speed_mode="uniform", timeout=10)

Description

Click

Parameters

element<str>The target element.

index<int>The index of the control when more than one is found.

parent_element<str>The parent element.

simulate<bool>Indicates whether to simulate a click.

button<str>The mouse button.

Options:

  • Left: left-click

  • Right: right-click

offset_x<int>The horizontal offset.

offset_y<int>Vertical offset.

move_mode<str>The movement mode of the mouse pointer when clicking (applies only when simulate=True).

Options:

  • without-track: The pointer instantly moves to the control and clicks it.

  • with-track: The pointer follows a simulated, human-like path to the control and clicks it.

speed_mode<str>The speed mode for mouse movement. This parameter only takes effect when simulate=True and move_mode="with-track".

  • uniform: Uniform motion

timeout<int>The timeout period.

Sample call: rpa.app.chrome.ChromeTab.click

# Notes:
# 1. Ensure the Alibaba Cloud RPA Chrome extension is installed and enabled.
# 2. Before use, ensure the page element has been captured with the capture control.
# 3. If simulate=True, the method simulates a mouse click, which requires the page element to be in the visible area.
# 4. If simulate=False, the method sends a click command directly to the element.
# Example:
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
page.click('login button-chrome')

(Deprecated) input_text

input_text(element, value, index=1, parent_element=None, simulate=True, replace=True, sent_raw=False, wait_mili_seconds=20, timeout=10)

Description

Enters text into an element.

Warning
  1. For client versions 4.10.3.1033 and later, we recommend using input_text_simulated or input_text_directed.

  2. This method remains functional, and existing automation workflows that use this method are not affected.

Parameters

element<str> The name of the control.

value<str> The text to enter.

index<int> The index of the control to use when multiple controls are found.

parent_element<str> The parent control object.

simulate<bool> Specifies whether to use simulated input.

replace<bool> Specifies whether to clear the element's content before entering text.

sent_raw<bool> Specifies whether to send raw keystrokes. This parameter applies only when simulate is False.

wait_mili_seconds<int> The interval between character inputs, in milliseconds. This parameter applies only to simulated input. The default is 20, and the maximum is 100. High values may cause a timeout.

timeout<int> The timeout, in seconds, for finding the control.

Example: rpa.app.chrome.ChromeTab.input_text

# Notes:
# 1. This method requires the Aliyun RPA Chrome extension to be installed and enabled.
# 2. Before using this method, you must capture the page element using the capture control feature.
# Sample code:
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
page.input_text('search-input','RPA')

input_text_simulated

input_text_simulated(element, value, index=1, mode='native', parent_element=None, replace=True, keystroke_interval=20, timeout=10)

Description

Simulates text input.

Note

This feature is available in client version 4.10.3.1033 and later.

Parameters

element<str>The name of the element.

value<str>The text to enter.

index<int>If multiple elements are found, specifies the index of the element to use. The default is 1.

mode<str>The input mode. Supported values are native, cdp, and driver.

  • native: Uses the operating system API to enter text.

  • cdp: Uses the browser extension to simulate typing.

  • driver: Uses the driver to simulate keyboard input.

    Important

    The driver mode supports only uppercase and lowercase English letters, numbers, and special characters on the keyboard. It does not support other characters, such as Chinese.

    Important

    To use driver mode, run the Alibaba Cloud RPA client with administrator privileges.

parent_element<str>The parent element object.

replace<bool>Specifies whether to clear existing content before entering new text.

keystroke_interval<int>The interval between keystrokes, in milliseconds. This parameter only applies in simulated input mode. The default is 20 and the maximum is 100. A high value may cause a timeout.

timeout<int>The timeout, in seconds, for finding the element.

Example

# Notes:
# 1. This method requires the Alibaba Cloud RPA Chrome browser extension to be installed and enabled.
# 2. Before use, capture the page element.

url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)

page.input_text_simulated('search-input','Alibaba Cloud RPA')

input_text_directed

input_text_directed(element, value, index=1, parent_element=None, replace=True, timeout=10)

Method

Enters text by directly modifying the HTML attributes of an element.

Note

This feature is available in client versions 4.10.3.1033 and later.

Important
  1. This method is fast, but its success depends on the web page's front-end implementation, so it may not work on all pages.

  2. For better compatibility, use input_text_simulated.

Parameters

element<str> The name of the element.

value<str> The text to enter.

index<int> The index of the element to use if multiple elements are found.

parent_element<str> The name of the parent element.

replace<bool> Specifies whether to clear the existing content before entering text.

timeout<int> The maximum time in seconds to wait for the element.

Example

# Notes:
# 1. Ensure the Aliyun RPA Chrome extension is installed and enabled.
# 2. Ensure you have captured the required page elements.
# Example:

url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)

page.input_text_directed('search-input','Aliyun RPA')

input_hotkeys

input_hotkeys(element, value, index=1, parent_element=None, timeout=10)

Description

Presses a hotkey. For details, see input_hotkey usage and virtual key code list.

Parameters

element<str>The target element.

value<str>The virtual key code to send.

index<int>The index of the element to use when multiple matches are found.

parent_element<str>The parent element.

timeout<int>The timeout for this action.

Element download

download_by_element(path, element, index=1, parent_element=None, wait=True, suffix=None, complete_timeout=120)

Description

Downloads a file via a control and waits for the download to complete. You must first go to chrome://settings/ and disable the "Ask where to save each file before downloading" setting.

Parameters

path<str>Path where the file will be saved.

element<str>The control.

index<int>The index of the control to use when multiple are found.

parent_element<Element>The parent element.

complete_timeout<int>The timeout for the operation to complete, in seconds.

wait<bool>Specifies whether to wait for the operation to complete.

suffix<str>The filename suffix format.

Optional:

  • datetime: Stores a date and time (year, month, day, hour, and minute).

  • date: Stores a date (year, month, and day).

Example: rpa.app.chrome.ChromeTab.download_by_element

# Notes:
# 1. Install and enable the Alibaba Cloud RPA Chrome extension.
# 2. Before running this code, use the capture element feature to capture the download button and verify the element is valid.
# Example:
url = 'http://www.cninfo.com.cn/new/disclosure/detail?plate=hke&orgId=9900042435&stockCode=09988&announcementId=1209275224'
page = rpa.app.chrome.create(url)
download_path = r'D:\Alibaba-SW-Public-Information.pdf'
page.download_by_element(download_path,'announcement download-chrome')

Upload

upload(element, file, index=1, parent_element=None, timeout=10)

Method description

Upload file

Parameters

element<str>The control.

file<str>The path to the file to upload.

index<int>The index of the control to use if more than one is found.

parent_element<str>The parent element.

timeout<int>The timeout value.

Example: rpa.app.chrome.ChromeTab.upload

# Notes:
# 1. Make sure you have installed and enabled the Alibaba Cloud RPA Chrome extension.
# 2. Before using this method, capture the upload button on the page using capture control and verify its availability.
# Code sample:
url = 'https://duguang.aliyun.com/experience?type=standard&subtype=idcard#intro'
page = rpa.app.chrome.create(url)
upload_path = r'D:\2_test_file_archive\OCR_ID_card_recognition.jpg'
page.upload('Upload Image-chrome',upload_path)

Text

text(element=None, index=1, parent_element=None, timeout=10)

Description

Get text

Parameters

element<str>The control.

index<int>The index of the control to select if multiple are found.

parent_element<str>The parent element.

timeout<int>The timeout duration.

Return value

Returns the text of the specified control, or all text in the browser by default.<str>

Code sample rpa.app.chrome.ChromeTab.text

# Notes:
# 1. Make sure the Alibaba Cloud RPA Chrome extension is installed and enabled.
# 2. Make sure you have captured the page element using the capture control feature.
# Example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
text = page.text(element='Bottom of page - pre-sales consultation-chrome')

HTML

html(element=None, index=1, parent_element=None, timeout=10)

Description

Get HTML

Parameters

element<str>The name or ID of the element.

index<int>The index of the control to select when multiple controls match.

parent_element<str>The parent element.

timeout<int>The timeout period.

Return value

Returns the html of the specified control, or of the entire page if none is specified.<str>

Example: RPA.app.Chrome.ChromeTab.html

# Notes:
# 1. Make sure the Alibaba Cloud RPA Chrome extension is installed and enabled.
# 2. Make sure the page element has been captured using the capture control.
# Example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
html = page.html('Bottom of page-pre-sales consultation-chrome')

Value

value(element, index=1, parent_element=None, timeout=10)

Description

Get the value

Parameters

control<str>The control

index<int>Specifies which control to use when multiple controls are found.

parent_element<str>The parent element.

timeout<int>The timeout duration.

Example: rpa.app.chrome.ChromeTab.value

# Notes:
# 1. Ensure you have installed and enabled the Alibaba Cloud RPA Chrome extension.
# 2. Ensure you have captured the page element using the capture control feature.
# Example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
value = page.value('Bottom of page - pre-sales consultation-chrome')

Option

option(element, text, index=1, parent_element=None, type='match', timeout=10)

Method

Select from the drop-down list.

Parameters

control<str>The control.

text<str>The selected content.

index<int>The index of the control to use if multiple are found.

type<str>The match type.

Options:

  • match → fuzzy match

  • full → exact match

  • regex → regex match

parent_element<str>The parent element.

timeout<int>The timeout period.

Important

Use this method only for HTML select elements, like the one shown below. To handle other types of drop-down lists, see Example: Dynamic selection in a drop-down list.

设置下拉框选项_2

Sample code: rpa.app.chrome.ChromeTab.option

# Notes:
# 1. This method requires the Alibaba Cloud RPA Chrome extension.
# 2. Before using this method, use the capture control feature to capture a dropdown list (an HTML  tag).
# 3. Ensure the dropdown list contains the specified text option.
# Code sample:
url = 'https://kyfw.12306.cn/otn/leftTicket/init'
page = rpa.app.chrome.create(url)

page.option('dropdown-list-chrome','00:00--06:00')

get_checked_state

get_checked_state(element, index=1, parent_element=None, timeout=10)

Description

Get the checked state

Parameters

element<str>The control.

index<int>The index of the control to select when multiple matches are found.

parent_element<str>The parent element.

timeout<int>Timeout period.

Return value

Returns the checked state <boolean>

Example: rpa.app.chrome.ChromeTab.get_checked_state

# Notes:
# 1. Ensure the Alibaba Cloud RPA Chrome extension is installed and enabled.
# 2. Ensure you have recorded the page element using the capture control.
# Example:
url = 'https://kyfw.12306.cn/otn/leftTicket/init'
page = rpa.app.chrome.create(url)
check_state = page.get_checked_state('Checkbox - high-speed train-chrome')

set_checked_state

set_checked_state(element, value=True, index=1, parent_element=None, timeout=10)

Description

Set the checked state

Parameters

element<str>The control

value<bool>true checks the control; false unchecks it.

index<int>The index of the control to select if multiple are found.

parent_element<str>The parent element.

timeout<int>The timeout period.

Example: rpa.app.chrome.ChromeTab.set_checked_state

# Notes:
# 1. Ensure you have installed and enabled the Alibaba Cloud RPA Chrome extension.
# 2. Ensure you have recorded the page element using capture control.
# Example:
url = 'https://kyfw.12306.cn/otn/leftTicket/init'
page = rpa.app.chrome.create(url)
page.set_checked_state('checkbox-high-speed-train-chrome', value=True)

Attribute

attr(element, attrname, index=1, parent_element=None, timeout=10)

Method

Get Property

Parameters

control<str>The control

index<int>The index of the control to select if multiple controls match.

parent_element<str>The parent control.

timeout<int>The timeout duration.

Return value

Returns the attribute value as a string.

Example: rpa.app.Chrome.ChromeTab.attr

# Notes:
# 1. Ensure that the Alibaba Cloud RPA Chrome extension is installed and enabled.
# 2. Ensure that the page element has been recorded using the capture control feature.
# Sample code:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
attribute = page.attr('login button-chrome','class')

process_alert

process_alert(option='ok', element=None, simulate=True, index=1, parent_element=None, timeout=10)

Description

Dialog box clicks.

Parameters

value<str>The action to perform on the dialog box.

Optional:

  • OK: Click OK to confirm the action.

  • Cancel: Click Cancel to cancel the action.

element<str>The element to click; if omitted, the browser pop-up is clicked.

index<int>The index of the control to use if more than one is found.

parent element<Element>The parent element.

timeout<int>Timeout period.

Code sample: rpa.app.chrome.ChromeTab.process_alert

# Notes:
# 1. Install and enable the Alibaba Cloud RPA Chrome extension.
# 2. This method only handles confirm or alert pop-ups.
# Example:
page = rpa.app.chrome.catch('W3School TIY Editor', mode='title', pattern='contain')
page.click('Trigger pop-up')
page.process_alert()
Note

Creating a pop-up:

  1. Open the W3Schools page.

  2. In the left script pane, enter the HTML script.

  3. Click run code. A pop-up button appears on the right.

1695718066756_40BCDD34-2CB3-40ab-A8FE-3A907D64CDB4.png

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script>
function myFunction()
{
    alert("Here is a pop-up message!");
}
</script>
</head>
<body>

<input type="button" onclick="myFunction()" value="Show Pop-up">

</body>
</html>

process_prompt

process_prompt(text, option='ok', element=None, simulate=True, index=1, parent_element=None, timeout=10)

Method description

Enter text in the input box and click.

Parameters

text<str>The input string.

option<str>The input box to click.

Options:

  • OK: Click OK.

  • Cancel: Click Cancel.

element<str>The element to click. If omitted, this defaults to clicking the browser popup.

simulate<bool>Specifies whether to simulate the operation.

index<int>The control's index if multiple are found.

parent_element<Element>The parent element.

timeout<int>Timeout duration.

Code sample: rpa.app.chrome.ChromeTab.process_prompt

# Notes:
# 1. You must install and enable the Alibaba Cloud RPA Chrome extension to use this method.
# 2. This method handles only prompt dialogs.
# Example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
page.execute_js('prompt("Enter your content:","")')
page.process_prompt('RPA_TEST')

Pos

pos(element, index=1, parent_element=None, timeout=10)

Method description

Get the coordinates of the control.

Parameters

element<str>Control

index<int>Specifies the control's index if multiple exist.

parent_element<str>The parent element.

timeout<int>The timeout duration.

Important

To make the control visible on the screen, you may need to:

  1. Activate the browser tab using activate.

  2. Scroll the control into view using scroll_into_view or scroll.

Code sample - rpa.app.chrome.ChromeTab.pos-

# Notes:
# 1. Ensure the Alibaba Cloud RPA Chrome extension is installed and enabled.
# 2. This method returns the coordinates of the page element relative to the top-left corner of the screen. Therefore, moving the browser window will change these coordinates.
# Code example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
pos = page.pos('login button-chrome')

Screenshot

screenshot(element, file, index=1, parent_element=None, timeout=10)

Description

Screenshot

Parameters

element<str>Control.

file<str>Path to the screenshot file.

index<int>The index of the control to select when multiple are found.

parent_element<str>The parent control object.

timeout<int>The timeout duration.

Important

The control must be in a visible state. You may need to take the following steps:

  1. Ensure the browser tab is active using activate.

  2. Scroll the control into view using scroll_into_view or scroll.

Example: rpa.app.chrome.ChromeTab.screenshot

# Notes:
# 1. Ensure the Aliyun RPA Chrome extension is installed and enabled.
# 2. Before using this method, ensure you have recorded the page element using capture control.
# Example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
save_path = r'D:\Alibaba Cloud footer text screenshot.jpg'
page.screenshot('Bottom of page - pre-sales consultation-chrome',save_path)

Mouse_move

mouse_move(element, index=1, parent_element=None, timeout=10)

Description

Hover

Parameters

element<str>The target control.

index<int>The index of the control to select if multiple are found.

parent_element<str>The parent element.

timeout<int>The timeout duration.

Example: rpa.app.chrome.ChromeTab.mouse_move

# Notes:
# 1. Ensure the Alibaba Cloud RPA Chrome extension is installed and enabled.
# 2. Before using this method, ensure the page element has been captured using the capture control feature.
# Example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
page.mouse_move('Bottom of page - pre-sales consultation-chrome')

isvisible

isvisible(element, index=1, parent_element=None, timeout=10)

Method description

Checks whether the control is visible.

Parameters

element<str>The target element.

index<int>The index of the control to select when multiple matches are found.

parent_element<str>The parent element.

timeout<int>Timeout period.

Return value

Returns whether the component is visible.<boolean>

Example: rpa.app.chrome.ChromeTab.isvisible

# Notes:
# 1. Ensure the Alibaba Cloud RPA Chrome extension is installed and enabled.
# 2. Before using this method, ensure you have captured the page element using capture control.
# 3. This method checks if a page element is visible. If the page element does not exist, it throws a control timeout exception.
# This code sample opens a web page, hides a specific page element using JavaScript, and then calls this method to check its visibility.
url = 'www.baidu.com'
page = rpa.app.chrome.create(url)
js = """
function set_display(){
    var div1 = document.getElementById("su");
    div1.style.display = "none";
};
set_display()
"""
page.execute_js(js)

flag = page.isvisible('Baidu Search-chrome')

Drag

drag(element, x=0, y=0, speed_mode='uniform', index=1, parent_element=None, timeout=10)

Description

Drag the element by a specified offset.

Parameters

element<str>The control element

x<int>x-axis offset

y<int> — y-axis offset

speed_mode<str>Specifies the speed mode for the drag operation.

  • uniform: Drags the element at a constant speed.

  • fast-slow-pause: Mimics a human-like drag by accelerating, decelerating, and then pausing to align.

index<int>The index of the control to select if multiple matches are found.

parent_element<str>The parent control object.

timeout<int>The timeout duration.

Sample call: rpa.app.chrome.ChromeTab.drag-

# Notes:
# 1. Ensure you have installed and enabled the Alibaba Cloud RPA Chrome extension.
# 2. Ensure the page element has been recorded using capture control before using this method.
# Example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
page.drag('Login button-chrome',x=-500,y=100)

(Deprecated) clear_input

clear_input(element, index=1, parent_element=None, timeout=10)

Description

Clears the value of an input box.

Warning
  1. For client versions 4.10.3.1033 and later, use clear_input_simulated or clear_input_directed.

  2. This method remains functional and does not affect existing automation processes.

Parameters

element<str> The name of the control.

index<int> The index of the control to use if multiple matching controls are found.

parent_element<str> The parent control object.

timeout<int> The maximum time in seconds to wait for the control.

Example

# Notes:
# 1. Ensure you have installed and enabled the Alibaba Cloud RPA Chrome extension.
# 2. Before using this method, ensure you have captured the page element using the capture control feature.
# Example:
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
page.clear_input('search-input')

clear_input_simulated

clear_input_simulated(element, index=1, parent_element=None, mode = 'native', timeout=10):

Description

Clears the content of an input box by simulating user input.

Note

This feature is available in Alibaba Cloud RPA Client versions 4.10.3.1033 and later.

Parameters

element<str> The name of the control.

index<int> The index of the control to use when multiple controls are found.

parent_element<str> The parent control object.

mode<str> The input mode. Supported values are 'native', 'cdp', and 'driver'.

  • native: Uses the operating system interface to clear the content.

  • cdp: Uses the browser extension to simulate clearing the content.

  • driver: Uses the driver to simulate keyboard actions to clear the content.

    Important

    The 'driver' mode requires the Alibaba Cloud RPA Client to be run as an administrator.

timeout<int> The timeout in seconds for finding the control.

Example rpa.app.chrome.ChromeTab.clear_input_simulated

# Notes:
# 1. The Alibaba Cloud RPA Chrome extension must be installed and enabled.
# 2. Before calling this method, you must capture the page element by using the capture control feature.
#
# The following code enters text into an input box and then clears it.
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
page.input_text_simulated('search-input','Alibaba Cloud RPA')
page.clear_input_simulated('search-input')

clear_input_directed

clear_input_directed(element, index=1, parent_element=None, timeout=10)

Description

Clears the content of an input box by directly modifying its HTML attributes.

Note

This feature is available in client versions 4.10.3.1033 and later.

Important
  1. This method is fast but may fail depending on the front-end implementation of the target web page.

  2. For better compatibility, use clear_input_simulated.

Parameters

element<str> The name of the control.

index<int> The index of the control to use if multiple matching controls are found.

parent_element<str> The parent control to search within for the target control.

timeout<int> The maximum time to wait for the control, in seconds.

Code sample

# Notes:
# 1. The Alibaba Cloud RPA Chrome extension must be installed and enabled.
# 2. Record the page element using the capture control feature before calling this method.
# Example:
# 1. Enter text into the input box.
# 2. Call this method to clear the content.

url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
page.input_text_simulated('search-input','Alibaba Cloud RPA')
page.clear_input_directed('search-input')