Get Element Value
Gets the element value from the web page.
Command availability: IBM RPA SaaS and IBM RPA on premises
Script syntax
IBM RPA's proprietary scripting language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.
webGet --selector(WebFieldElementSelectors) --id(String) --name(String) --css(String) --xpath(String) [--simulatehuman(Boolean)] [--timeout(TimeSpan)] (String)=value
Dependencies
Use the Start Browser (webStart
) command to start a browser or use the Find Internet Explorer Browser (findBrowser
)
command to attach the Microsoft Internet Explorer before using this command.
Input parameter
The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.
Designer mode label | Script mode name | Required | Accepted variable types | Description |
---|---|---|---|---|
Selector type | selector |
Required |
WebElementSelectors |
Type of selector to identify elements in a web page. See the selector parameter options for more details. |
Element id | id |
Required when the Selector type parameter is Id, IdAndName |
Text |
The ID attribute value to match and get the element's value. |
Element name | name |
Required when the Selector type parameter is Name, IdAndName |
Text |
The Name attribute value to match and get the element's value. |
Element CSS | css |
Required when the Selector type parameter is CssSelector |
Text |
The CSS selector to match and get the element's value. |
Xpath | xpath |
Required when the Selector type parameter is XPath |
Text |
The XML path value to match and get the element's value. |
Simulate human | simulatehuman |
Optional |
Boolean |
This parameter does not change the behavior of the command. |
Timeout | timeout |
Optional |
Time Span , Number , Text |
Maximum wait time for response. The default timeout is 5 seconds. |
selector
parameter options
The following table displays the options available for the selector
input parameter. The table shows the options available when working in Script mode and the equivalent label in the Designer mode.
Designer mode label | Script mode name | Description |
---|---|---|
Id | Id |
Matches the element based on the ID attribute value. |
Name | Name |
Matches the element based on the Name attribute value. |
Css | CssSelector |
Matches the element based on the CSS selector value. |
XPath | XPath |
Matches the element based on the XML path in the HTML root. |
Id and name | IdAndName |
Matches the element based on the Id and name attribute value. |
Output parameter
Designer mode label | Script mode name | Accepted variable types | Description |
---|---|---|---|
Value | value |
Text |
Returns the value obtained from the element. |
Example
Example 1: The following code example demonstrates how to get the element's value from a web page. The command opens a browser, navigates to a website, uses the Css
selector to get the value in the specified element,
and then log the value of the element.
defVar --name elementText --type String
defVar --name webpage --type String --value "http://www.example.com/"
defVar --name browser --type Browser
// Launches the Google Chrome browser
webStart --name browser --type "Chrome" --userprofilepreferences "AutomationOptimized" browser=value
// Navigates to the web page with the text elements
webNavigate --url "${webpage}"
webGet --selector "CssSelector" --css cssValue --simulatehuman --timeout "00:00:10" elementText=value
// Logs the element value
logMessage --message "The element return: ${elementText}" --type "Info"
webClose --name browser
Example 2: In this example, the command uses a different selector to obtain the value of a specified element, in this case, it uses the XPath
selector. As this element is not unique, and it is inside an iframe,
the XPath
value must address what element the command will obtain.
defVar --name elementText --type String
defVar --name webpage --type String --value "http://www.example.com/"
defVar --name xpathSelector --type String --value "//iframe[@name=\'example\']\r\n"
// Launches the Google Chrome browser
webStart --name browser --type "Firefox" --userprofilepreferences "UserProfileOptmized"
// Navigates to the web page with the text elements
webNavigate --url "${webpage}"
webGet --selector "XPath" --xpath "${xpathSelector}" --timeout "00:00:10" elementText=value
// Logs the element value
logMessage --message "The element return: ${elementText}" --type "Info"
webClose --name browser
Limitations
When interacting with a not unique web element, using XPath or CSS selectors that is inside an IFrame, it is necessary to specify which element inside the IFrame the command will interact with. Otherwise, only the first element will be found.