ChromeTab

Updated at:

close

close(script_timeout=10)

Description

Closes the browser object.

Parameters

script_timeout<float> The script execution timeout period. The default value is 10 s.

Example: rpa.app.chrome.ChromeTab.close

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an example:
page = rpa.app.chrome.create('www.aliyun.com')
page.close(script_timeout=10)

navigate

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

Description

Navigates to a specified URL.

Parameters

url<str> The URL to open.

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

timeout<int> The timeout period for waiting. The default value is 100 s.

Example: rpa.app.chrome.ChromeTab.navigate

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an example:
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
page.navigate('help.aliyun.com/document_detail/175379.html')

back

back(wait=True, timeout=100)

Description

Navigates back in the browser history.

Parameters

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

timeout<int> The timeout period for waiting. The default value is 100 s.

Example: rpa.app.chrome.ChromeTab.back

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an example:
url = 'www.baidu.com'
page = rpa.app.chrome.create(url)
page.input_text('baidu_input_box','Alibaba Cloud')
page.click('baidu_search_button', simulate=True)
page.back()

forward

forward(wait=True, timeout=100)

Description

Navigates forward in the browser history.

Parameters

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

timeout<int> The timeout period for waiting. The default value is 100 s.

Example: rpa.app.chrome.ChromeTab.forward

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an 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()

Description

Activates the page.

Example: rpa.app.chrome.ChromeTab.activate

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an example:
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
page.activate()

url

url()

Description

Retrieves the URL of the current page.

Return value

Returns the URL.<str>

Example: rpa.app.chrome.ChromeTab.url

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an example:
page = rpa.app.chrome.create('www.aliyun.com')
url = page.url()

title

title()

Description

Retrieves the title of the current page.

Return value

Returns the title.<str>

Example: rpa.app.chrome.ChromeTab.title

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an example:
page = rpa.app.chrome.create('www.aliyun.com')
title= page.title()

reload

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

Description

Refreshes the page.

Parameters

bypass_cache<bool> Specifies whether to ignore the cache.

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

timeout<int> The timeout period for waiting. The default value is 100 s.

Example: rpa.app.chrome.ChromeTab.reload

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an 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

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an 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

Starts listening for web page requests.

Parameters

url<str> The URL to listen for. The default value is an empty string, which means all URLs are monitored.

use_regular<bool> Specifies whether to use a regular expression for URL matching.

capture_types<list> The types of requests to listen for. Supported types include XHR/Fetch, XHR, Fetch, JS, CSS, Image, Font, Document, Websocket, and Other.

Return value

The index key for the web request listener. You can use this key to retrieve the listening results or stop the listener.<string>

Example: rpa.app.chrome.ChromeTab.network_capture_start

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an example:
# Open the Alibaba Cloud page in Google Chrome.
page = rpa.app.chrome.create('www.aliyun.com')
# Start listening for web page requests.
capture_key = page.network_capture_start(url='', use_regular=False, capture_types=[])
# Refresh the page.
page.reload()
# Get the results from the web request listener.
web_respond_body = rpa.app.chrome.get_network_capture_result(capture_key)
# Stop listening for web page requests.
rpa.app.chrome.network_capture_stop(capture_key)
# Record the information in a log.
rpa.console.logger.info(web_respond_body)

wait_load_completed

wait_load_completed(timeout=100)

Description

Waits for the page to finish loading.

Parameters

timeout<int> The timeout period for waiting. The default value is 100 s.

Example: rpa.app.chrome.ChromeTab.wait_load_completed

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an example:
page = rpa.app.chrome.create('www.aliyun.com')
page.wait_load_completed()

copy

copy()

Description

Performs a copy operation on the current page.

Return value

Returns whether the operation was successful.<bool>

Example: rpa.app.chrome.ChromeTab.copy

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. This method only executes the copy instruction. Select the content to copy using another method before calling this method.
# 3. This method writes the content to the system clipboard.
# The following code provides an example. In this example, the content of a cell is double-clicked to select the text, and then the copy operation is performed:
page = rpa.app.chrome.create('https://help.aliyun.com/document_detail/175379.html')
page.double_click('queryClientViews-chrome')
page.copy()

paste

paste()

Description

Performs a paste operation on the current page.

Return value

Returns whether the operation was successful.<bool>

Example: rpa.app.chrome.ChromeTab.paste

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. This method only executes the paste instruction. Select the area to paste into using another method before calling this method.
# 3. This method pastes the latest content from the clipboard into the selected area.
# The following code provides an example. In this example, after copying the cell content, the search box is clicked, and then the paste action is performed:
page = rpa.app.chrome.create('https://help.aliyun.com/document_detail/175379.html')
page.double_click('queryClientViews-chrome')
page.copy()
page.click('document_search_box-chrome')
page.paste()

cut

cut()

Description

Performs a cut operation on the current page.

Return value

Returns whether the operation was successful.<bool>

Example: rpa.app.chrome.ChromeTab.cut

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. This method only executes the cut instruction. Select the content to cut using another method before calling this method. If the content cannot be cut, this action has no effect.
# 3. This method writes the content to the system clipboard.
# The following code provides an example. In this example, you must first manually open the Baidu home page and enter any content in the input box.
# The program will double-click the input box to select the text and then perform the cut action:
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

Executes JavaScript code.

Parameters

code<str> The JavaScript code.

element<str> The control. The JavaScript code is executed within the domain of this control. This is used for cross-domain operations.

index<int> If there are multiple controls, specify the index of the control.

timeout<int> The timeout period.

Return value

Returns the execution result as a JSON string.<str>

Example: rpa.app.chrome.ChromeTab.execute_js

# Note: Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# This method must be called on a ChromeTab instance object.
# The following code provides an 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)

Description

Retrieves a table from the page.

Parameters

type<str> The match type.

Options:

  • index: Matches by index.

  • Text: text-matching.

  • html: Matches by HTML.

return_type<str> The return type.

Options:

  • Text: Text Type

  • html: HTML format

Return Value

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

Example: rpa.app.chrome.ChromeTab.table

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. This method gets a standard table (with the HTML tag `table`) from the page by index (starting from 1) or regular expression.
# The following code provides an example. After running, it will get the first table on the web page (the content of the first `table` tag in top-to-bottom HTML order):
page = rpa.app.chrome.create('https://help.aliyun.com/document_detail/175379.html')
table_data = page.table(1)

scroll

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

Description

Scrolls the page.

Parameters

height<int> If set, scrolls by the specified height. Otherwise, scrolls to the bottom of the page.

element<str> The control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<Element> The parent control object.

timeout<int> The timeout period.

direction<str> The scroll direction.

Options:

  • left: Scrolls left.

  • top: Scrolls down.

Example: rpa.app.chrome.ChromeTab.scroll

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. If no parameters are passed or the parameter is set to 0, this method scrolls the page slider to the bottom.
# The following code provides an example:
page = rpa.app.chrome.create('https://help.aliyun.com/document_detail/175379.html')
page.scroll()
# To scroll a list information bar on the page, you need to pass parameters such as `height` and `element`. For more information, see the following example.
page.scroll(height=200, element='list_bar_scroll', index=1, parent_element=None, timeout=10, direction='top')
Important

The control to be recorded is the scrollable list bar itself.scroll_1

get_element_by_name

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

Description

Retrieves an element object.

Parameters

element<str> The control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<Element> The parent control object.

timeout<int> The timeout period.

Return value

Returns the control object.<Element>

Example: rpa.app.chrome.ChromeTab.get_element_by_name

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Note: Before use, you must capture the elements on the page using the control capturing feature.
# The following code provides an 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

Retrieves a control based on a CSS expression.

Parameters

css<str> The CSS expression.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Return value

Returns the control object.<Element>

Example: rpa.app.chrome.ChromeTab.get_element_by_css

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. This method uses a CSS selector to locate the element to operate on. Use a standard CSS selector expression.
# The following code provides an example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
css_selector = "span.lake-fontsize-11" # Represents a span tag with the class value lake-fontsize-11
element = page.get_element_by_css(css_selector)
text = element.text()

count

count(element, parent_element=None)

Description

Retrieve the number of controls

Parameters

element<str> The control.

parent_element<str> The parent control object.

Example: rpa.app.chrome.ChromeTab.count

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. After getting similar control elements using the capture similar controls feature, this method is often used to count the number of controls.
# The following code provides an example:
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
element_count = page.count('logon_button-chrome')

wait_loaded

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

Description

Waits for a control to load.

Parameters

element<str> The control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

ignore_error<bool> Specifies whether to ignore errors.

Example: rpa.app.chrome.ChromeTab.wait_loaded

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an 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)

Description

Waits for a control to disappear.

Parameters

element <str> The specified control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Example: rpa.app.chrome.ChromeTab.wait_disappear

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an 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

Handles a JavaScript dialog box.

Parameters

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

Options:

  • ok: Clicks OK.

  • cancel: Clicks Cancel.

text<str> The text to enter into the dialog box.

Example: rpa.app.chrome.ChromeTab.handle_javascript_dialog

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# The following code provides an example:
page = rpa.app.chrome.catch('W3School Tryit Editor', mode='title', pattern='contain')
page.click('show_popup_button')
page.handle_javascript_dialog()
Note

Steps to create a page with a pop-up dialog box:

  1. First, open the W3School page.

  2. Write the HTML script content in the script box on the left.

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

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

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script>
function myFunction()
{
    alert("Here I am to bother you~!");
}
</script>
</head>
<body>

<input type="button" onclick="myFunction()" value="Click me for a 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 control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

simulate<bool> Specifies whether to simulate a click.

button<str> The mouse button.

Options:

  • left: Left button.

  • right: Right button.

offset_x<int> The horizontal offset.

offset_y<int> The vertical offset.

move_mode<str> The mouse movement mode for the click. This parameter is valid only when simulate=True.

Options:

  • without-track: The mouse moves to the control without a track and clicks it.

  • with-track: The mouse simulates a track to move to the control and click it.

speed_mode<str> The speed mode of the mouse movement. This parameter is valid only when simulate=True and move_mode=with-track.

  • uniform: Moves at a uniform speed.

timeout<int> The timeout period.

Example: rpa.app.chrome.ChromeTab.click

# Notes:
# 1. Make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before you use this method, make sure that you have recorded the page elements using the control capturing feature.
# 3. If simulate=True, a simulated mouse click is performed. This requires the corresponding page element to be in the visible area.
# 4. If simulate=False, a click instruction is sent directly to the element.
# Example:
url = 'www.aliyun.com'
page = rpa.app.chrome.create(url)
page.click('Logon_Button-Chrome')

input_text (deprecated)

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

Description

Enter text

Warning
  1. For client versions 4.10.3.1033 and later, use input_text_simulated or input_text_directed.

  2. This method can still be used. Automation flows that already use this method are not affected.

Parameters

element<str> The control name.

value<str> The content to enter.

index<int> If there are multiple controls, specify the index of the control to operate on.

parent_element<str> The parent control object.

simulate<bool> Specifies whether to simulate input.

replace<bool> Specifies whether to clear the previous content.

sent_raw<bool> Specifies whether to send raw keystrokes. This parameter is valid only in non-simulated mode.

wait_mili_seconds<int> The interval, in milliseconds, between character inputs. This parameter is valid only for simulated input. The default value is 20 and the maximum value is 100. A large value may cause a timeout.

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

Example: rpa.app.chrome.ChromeTab.input_text

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
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

Enters text using simulation.

Note

This feature is available in client versions 4.10.3.1033 and later.

Parameters

element<str> The control name.

value<str> The content to enter.

index<int> If there are multiple controls, specify the index of the control to operate on.

mode<str> The input method. Only `native`, `cdp`, and `driver` are supported.

  • native: Uses the operating system interface to complete the input.

  • cdp: Uses the browser extension to simulate typing.

  • driver: Uses the driver to simulate keyboard input.

    Important

    For more information, see Limits on driver input.

parent_element<str> The parent control object.

replace<bool> Specifies whether to clear the previous content.

keystroke_interval<int> The interval, in milliseconds, between character inputs. This parameter is valid only for simulated input. The default value is 20 and the maximum value is 100. A large value may cause a timeout.

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

Example: rpa.app.chrome.ChromeTab.input_text_simulated

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:

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)

Description

Enters text by modifying HTML attribute information.

Note

This feature is available in client versions 4.10.3.1033 and later.

Important
  1. This method executes quickly, but its usability depends on the frontend implementation of the web page. It may not work on all web pages.

  2. We recommend that you use input_text_simulated.

Parameters

element<str> The control name.

value<str> The content to enter.

index<int> If there are multiple controls, specify the index of the control to operate on.

parent_element<str> The parent control object.

replace<bool> Specifies whether to clear the previous content.

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

Example: rpa.app.chrome.ChromeTab.input_text_directed

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:

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

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

input_hotkeys

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

Description

Enters a keyboard shortcut. For more information, see Usage and list of virtual key codes for input_hotkey.

Parameters

element <str> control

value<str> The virtual key code.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

download_by_element

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

Description

Clicks a specified control to download a file and waits for the browser to finish downloading. The file is first downloaded to the browser's default download location and then automatically moved to the destination file path.

Note

We recommend that you disable the "Ask where to save each file before downloading" setting in your browser, as shown in the following figure.

image

  • If disabled: If a file with the same name exists, it is automatically overwritten.

  • If enabled: If a file with the same name exists in the browser's download location, a manual confirmation window appears, which affects the automation flow.

Parameters

path<str> The path where the file is saved.

element<str> The control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<Element> The parent control object.

complete_timeout<int> The timeout period.

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

suffix<str> The format of the suffix to automatically add to the filename. The following values are available:

  • datetime: Date and time (YYYYMMDDHHMM).

  • date: Date (YYYYMMDD).

Example: rpa.app.chrome.ChromeTab.download_by_element

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, you must first capture the download button on the page using the control capturing feature and verify that it is available.
# The following code provides an example:
url = 'https://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')

download_by_url

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

Description

Uses the browser to download a file from a specified URL and waits for the download to finish. The file is first downloaded to the browser's default download location and then automatically moved to the destination file path.

Note

We recommend that you disable the "Ask where to save each file before downloading" setting in your browser, as shown in the following figure.

image

  • If disabled: If a file with the same name exists, it is automatically overwritten.

  • If enabled: If a file with the same name exists in the browser's download location, a manual confirmation window appears, which affects the automation flow.

Parameters

url<str> The link to the file to download.

path<str> The path where the file is saved.

complete_timeout<int> The timeout period.

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

Example: rpa.app.chrome.ChromeTab.download_by_url

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# The following code provides an example. After running, it will download the corresponding file to the specified path:
url = 'https://www.cninfo.com.cn'
page = rpa.app.chrome.create(url)
download_url = 'https://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)

upload

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

Description

Uploads a file.

Parameters

element<str> The control.

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

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Example: rpa.app.chrome.ChromeTab.upload

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, you must first capture the upload button on the page using the control capturing feature and verify that it is available.
# The following code provides an example:
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

You can retrieve text

Parameters

element<str> The control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Return value

Returns the text. If no control is passed, it returns all text on the browser page.<str>

Example: rpa.app.chrome.ChromeTab.text

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
text = page.text(element='page_bottom-pre-sales_consulting-chrome')

html

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

Description

Retrieve the HTML.

Parameters

element<str> The control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Return value

Returns the HTML. If no control is passed, it returns all HTML on the browser page.<str>

Example: rpa.app.chrome.ChromeTab.html

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
html = page.html('page_bottom-pre-sales_consulting-chrome')

value

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

Description

Retrieves the value of an element.

Parameters

element<str> The control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Example: rpa.app.chrome.ChromeTab.value

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
value = page.value('page_bottom-pre-sales_consulting-chrome')

option

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

Description

Selects an option from a drop-down list.

Parameters

element<str> The control.

text<str> The content to select.

index<int> If there are multiple controls, specify the index of the control.

type<str> The match type.

Options:

  • match: Fuzzy match.

  • full: Exact match.

  • regex: Regex match.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Important

This method only supports operations on HTML `select` elements, as shown in the following figure. To operate on drop-down lists implemented in other ways, see Example: Dynamically select from a drop-down list.

设置下拉框选项_2

Example: rpa.app.chrome.ChromeTab.option

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, you must first capture the standard drop-down list element (with the HTML tag `select`) on the page using the control capturing feature.
# 3. Make sure that the corresponding text option exists in the drop-down list.
# The following code provides an example:
url = 'https://kyfw.12306.cn/otn/leftTicket/init'
page = rpa.app.chrome.create(url)

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

get_checked_state

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

Description

Retrieves the checked state of a control.

Parameters

element<str> The control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Return value

Returns the checked state.<bool>

Example: rpa.app.chrome.ChromeTab.get_checked_state

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
url = 'https://kyfw.12306.cn/otn/leftTicket/init'
page = rpa.app.chrome.create(url)
check_state = page.get_checked_state('checkbox-bullet_train-chrome')

set_checked_state

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

Description

Sets the checked state.

Parameters

element<str> The control.

value<bool> Pass `True` to check the box, or `False` to uncheck it.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Example: rpa.app.chrome.ChromeTab.set_checked_state

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
url = 'https://kyfw.12306.cn/otn/leftTicket/init'
page = rpa.app.chrome.create(url)
page.set_checked_state('checkbox-bullet_train-chrome', value=True)

attr

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

Description

Retrieves an attribute from an element.

Parameters

element<str> The control.

attrname<str> The attribute name.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Return value

Returns the attribute value.<str>

Example: rpa.app.chrome.ChromeTab.attr

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
attribute = page.attr('logon_button-chrome','class')

process_alert

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

Description

Clicks a button in a pop-up dialog box.

Parameters

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

Options:

  • ok: Clicks OK.

  • cancel: Clicks Cancel.

element<str> The control. If no control is passed, it clicks a button in a pop-up dialog box within the browser.

simulate<bool> Specifies whether to simulate the action.

index<int> If there are multiple controls, specify the index of the control.

parent_element<Element> The parent control object.

timeout<int> The timeout period.

Example: rpa.app.chrome.ChromeTab.process_alert

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. This method can only handle `confirm` or `alert` pop-up windows.
# The following code provides an example:
page = rpa.app.chrome.catch('W3School Tryit Editor', mode='title', pattern='contain')
page.click('show_popup_button')
page.process_alert()
Note

Steps to create a page with a pop-up dialog box:

  1. First, open the W3School page.

  2. Write the HTML script content in the script box on the left.

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

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

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script>
function myFunction()
{
    alert("Here I am to bother you~!");
}
</script>
</head>
<body>

<input type="button" onclick="myFunction()" value="Click me for a pop-up">

</body>
</html>

process_prompt

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

Description

Enters text into an input box and clicks a button.

Parameters

text<str> The content to enter.

option <str> Clicks the input box.

Options:

  • ok: Clicks OK.

  • cancel: Clicks Cancel.

element<str> The control. If no control is passed, it clicks a button in a pop-up dialog box within the browser.

simulate<bool> Specifies whether to simulate the action.

index<int> If there are multiple controls, specify the index of the control.

parent_element<Element> The parent control object.

timeout<int> The timeout period.

Example: rpa.app.chrome.ChromeTab.process_prompt

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. This method can only handle `prompt` pop-up windows.
# The following code provides an example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
page.execute_js('prompt("Please enter content:","")')
page.process_prompt('RPA_TEST')

pos

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

Description

Retrieves the coordinates of a control.

Parameters

element<str> The control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Important

The control must be visible on the screen. Therefore, you may need to use the following methods:

  1. The browser tab must be active. You can use activate.

  2. Use scroll_into_view or scroll to scroll the page.

Example: rpa.app.chrome.ChromeTab.pos

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. This method returns the coordinates of the page element with the top-left corner of the screen as the origin. This means that if you move the web page window, these coordinates will change.
# The following code provides an example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
pos = page.pos('logon_button-chrome')

screenshot

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

Description

Takes a screenshot.

Parameters

element<str> The control.

file<str> The path to save the screenshot.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Important

The control must be visible on the screen. Therefore, you may need to use the following methods:

  1. The browser tab must be active. You can use activate.

  2. Use scroll_into_view or scroll to scroll the page.

Example: rpa.app.chrome.ChromeTab.screenshot

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
save_path = r'D:\Alibaba_Cloud_bottom_text_screenshot.jpg'
page.screenshot('page_bottom-pre-sales_consulting-chrome',save_path)

mouse_move

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

Description

Moves the mouse over an element.

Parameters

element<str> The control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Example: rpa.app.chrome.ChromeTab.mouse_move

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
page.mouse_move('page_bottom-pre-sales_consulting-chrome')

isvisible

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

Description

Checks whether a control is visible.

Parameters

element<str> The control.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Return value

Returns whether the control is visible.<bool>

Example: rpa.app.chrome.ChromeTab.isvisible

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# 3. This method checks the visibility property of a page element. If the corresponding element does not exist on the page, a "wait for control timeout" exception is thrown.
# The following code provides an example. In this example, after opening the web page, JavaScript is used to set the specified page element to invisible, and then this method is used:
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

Drags an element by a specified offset.

Parameters

element<str> The control.

x<int> The offset on the x-axis.

y<int> The offset on the y-axis.

speed_mode<str> The speed mode for dragging.

  • uniform: Drags at a uniform speed.

  • fast-slow-pause: Accelerates the drag, then decelerates, and finally pauses for alignment. This simulates human dragging behavior.

index<int> If there are multiple controls, specify the index of the control.

parent_element<str> The parent control object.

timeout<int> The timeout period.

Example: rpa.app.chrome.ChromeTab.drag

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
url = 'https://help.aliyun.com/document_detail/175379.html'
page = rpa.app.chrome.create(url)
page.drag('logon_button-chrome',x=-500,y=100)

clear_input (deprecated)

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

Description

Clears 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 can still be used. Automation flows that already use this method are not affected.

Parameters

element<str> The control name.

index<int> If there are multiple controls, specify the index of the control to operate on.

parent_element<str> The parent control object.

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

Example: rpa.app.chrome.ChromeTab.clear_input

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an 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 using simulation.

Note

This feature is available in client versions 4.10.3.1033 and later.

Parameters

element<str> The control name.

index<int> If there are multiple controls, specify the index of the control to operate on.

parent_element<str> The parent control object.

mode<str> The input method. Only `native`, `cdp`, and `driver` are supported.

  • 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 the keyboard to clear the content.

    Important

    For more information, see Limits on driver input.

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

Example: rpa.app.chrome.ChromeTab.clear_input_simulated

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
# 1. First, enter text content.
# 2. Call this method to clear the entered content.

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 modifying HTML attribute information.

Note

This feature is available in client versions 4.10.3.1033 and later.

Important
  1. This method executes quickly, but its usability depends on the frontend implementation of the web page. It may not work on all web pages.

  2. We recommend that you use clear_input_simulated.

Parameters

element<str> The control name.

index<int> If there are multiple controls, specify the index of the control to operate on.

parent_element<str> The parent control object.

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

Example: rpa.app.chrome.ChromeTab.clear_input_directed

# Notes:
# 1. Before using this method, make sure that the Aliyun RPA extension for Chrome is installed and enabled.
# 2. Before use, make sure that you have recorded the page elements using the control capturing feature.
# The following code provides an example:
# 1. First, enter text content.
# 2. Call this method to clear the entered 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')