Get Image from the Web
Gets an image from the web page.
Command availability: IBM RPA SaaS and IBM RPA on premises
Description
Gets an image from an element in the web page. The command stores the image in the IBM RPA Studio's memory stream and returns an Image
value that contains this image as a .png
file during the script's runtime.
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.
webGetImage --selector(WebFieldElementSelectors) --id(String) --name(String) --css(String) --xpath(String) [--simulatehuman(Boolean)] [--timeout(TimeSpan)] (Image)=value
Dependencies
Before using the Get Image from the Web (webGetImage
) command, 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.
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 |
WebFieldElementSelectors |
Type of selector to identify the elements in the web page. See the selector parameter options. |
Image Id | id |
Required when the Selector type parameter is Id, IdAndName |
Text |
A text that contains the ID attribute value to match and get the element. |
Image Name | name |
Required when the Selector type parameter is Name, IdAndName |
Text |
A text that contains the Name attribute value to match and get the element. |
Image CSS | css |
Required when the Selector type parameter is CssSelector |
Text |
A text that contains the CSS selector to match and get the element. |
XPath | xpath |
Required when the Selector type parameter is XPath |
Text |
A text that contains the XML path value to match and get the element. |
Simulate Human | simulatehuman |
Optional |
Boolean |
This parameter does not change the behavior of the command. |
Timeout | timeout |
Optional |
Time Span , Number , Text |
Maximum waiting time for running the command. When blank, the default timeout is 5 seconds. |
Force Enable Scroll | forcescroll |
Optional when the Get Image From Full Page Scrennshot parameter is True |
Boolean |
Enable to change the page's source code to enable body scroll. This option changes the element to automatically adjust its height so the content can be fully displayed on the screen and the element can be clipped correctly. This change might affect the page's appearance while the command runs. Because of this, some elements in the page structure might not be displayed correctly. |
Get Image From Full Page Scrennshot | fromfullpage |
Optional |
Boolean |
Enable to get the full image if it is not freely visible in the preview window. |
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 |
---|---|---|---|
Image | value |
Image |
Returns an Image value that contains the image that is obtained from the web page. |
Example
The following code example demonstrates how to use the Get Image from the Web (webGetImage
) command to get an image from a css
selector.
defVar --name desktopPath --type String
defVar --name webImage --type Image
defVar --name imagePath --type String
defVar --name webpage --type String --value "https://www.ibm.com/docs/en/rpa/21.0"
defVar --name elementSelector --type String --value "#app > div > div > div > div > div.bx--masthead > div > header > div.bx--header__logo.bx--search-active > a > svg"
// Gets a folder path of the system. This folder path stores the image
getSpecialFolder --folder "Desktop" desktopPath=value
// Launches the Google Chrome browser
webStart --name browser --type "Chrome"
// Navigates to the web page
webNavigate --url "${webpage}"
// Waits until the element be available on the web page
webWaitElement --selector "CssSelector" --css "${elementSelector}"
// This command stores the image in memory during the script runtime
webGetImage --selector "CssSelector" --css "${elementSelector}" --simulatehuman webImage=value
// Saves the image on the desktop
saveImage --image ${webImage} --directory "${desktopPath}" --file ibm_logo --overwrite --format "Png" imagePath=value
// Logs the image file path
logMessage --message "Image path: ${imagePath}" --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.