Getting values from a web page
Learn how to develop an script to get values from a web page, such as table values, images, and texts.
About this task
In this tutorial, you develop an script to navigate to a web page, obtain a table, select a value in a multiple combination box, obtain an image from the web, and store this information as files in a system directory.
Before you begin
Install and configure the following items on your computer:
- IBM RPA Studio 20.12.0 or higher
- One of the supported browsers:
- Google Chrome
- Mozilla Firefox
- Internet Explorer
- Stable internet connection
- User with administrator access on Microsoft® Windows™
- Use the Designer development view
Procedure
Creating the directory
You need to create the directory that stores the files containing the information obtained from the web page:
-
Insert the Get System Folder Path command into the script.
- In the Folder input parameter, select the
My Documentsoption. - In the Path output parameter, insert the value
pathMyDocuments.
- In the Folder input parameter, select the
-
Insert the Create Directory command in the script.
- In the Path input parameter, insert the value
${pathMyDocuments}\rpa_challenge_tutorial. - In the Directory output parameter, insert the value
directoryObtainedFiles.
Starting the browser
Insert the commands to create a new instance of the browser:
- In the Path input parameter, insert the value
-
In the Home tab, click the New variable button to define a new variable.
- In the Name input parameter, insert the value
instanceName. - In the Variable Type input parameter, select the
Textoption. - In the Value input parameter, insert the value
browser-instance.
- In the Name input parameter, insert the value
-
Insert the Start Browser command into the script.
- In the Instance name input parameter, insert the variable
${instanceName}. - In the Browser Type input parameter, select a browser available on your machine.
The Close Browser command closes the web automation scope. It is automatically inserted into the script when saving the Start Browser command definition.
- In the Instance name input parameter, insert the variable
-
In the Close Browser command, insert the values:
- In the Instance name input parameter, insert the variable
${instanceName}. - Enable the Keep browser open input parameter.
Important: Insert all commands to manipulate web page elements between the Start Browser and Close Browser commands.
Navigating to the web page
Navigate to the IBM RPA Stock Market
web page:
- In the Instance name input parameter, insert the variable
-
Insert the Navigate command into the script.
- In the URL input parameter, insert the value
http://rpachallenge.com/assets/rpaStockMarket/index.html.
Manipulating elements
Start handling elements by waiting for all web page requests to load. With all requests loaded, you prevent the robot from interrupting its execution by not finding the necessary elements on the web page:
- In the URL input parameter, insert the value
-
Insert the Wait for Web Page Requests command in the script.
- In the Timeout input parameter, insert the value
00:00:30.
Getting the table from the web
Use the Get Web Table command to get the data table containing the country tax rates:
- In the Timeout input parameter, insert the value
-
Insert the Get Web Table command into the script.
- In the Selector Type input parameter, select the
Cssoption. - In the CSS input parameter, insert the value
body > div > div.center > div > div.items > table. - In the Timeout input parameter, insert the value
00:00:30. - In the Data Table output parameter, insert the value
ratesForCountries.
Writing on the file
You need to write the content you got from a web data table on a CSV file.
- In the Selector Type input parameter, select the
-
In the Home tab, click the New variable button to define a new variable.
- In the Name input parameter, insert the value
pathCsvFile. - In the Variable Type input parameter, select the
Textoption.
- In the Name input parameter, insert the value
-
Insert the Assign Variable command in the script.
- In the Variable input parameter, insert the variable
${pathCsvFile}. - In the Value input parameter, insert the value
${directoryObtainedFiles}\rates-per-country.csv.
- In the Variable input parameter, insert the variable
-
Insert the Write Table to File command in the script.
- Enable the Add Header input parameter.
- In the Data Table input parameter, insert the variable
${ratesForCountries}. - In the From Row input parameter, insert the value
1. - In the Delimiter input parameter, select the value
By Characters. - In the Separator input parameter, insert the value
,. - In the Path input parameter, insert the variable
${pathCsvFile}.
Selecting web elements
You need to use the Select Item in Combo Box command to select a value in the combination box.
-
Insert the Select Item in Combo Box command in the script.
- In the Search by input parameter, select the
Idoption. - In the ID input parameter, insert the value
country. - In the Select Option by input parameter, select the option
Value. - In the Value to Select input parameter, insert the value "
WEX Academy Inc.". - In the Timeout input parameter, insert the value
00:01:00.
- In the Search by input parameter, select the
-
Insert the Click on Web Page command in the script.
- In the Search for input parameter, select the
Cssoption. - In the CSS input parameter, insert the value
body > div > div.center > div > div.innercontainer > div.navbar2 > p > input[type=image]. - In the Timeout input parameter, insert the value
00:01:00.
Getting web elements
Use the Get Element Value command to get all data from the company selected before.
- In the Search for input parameter, select the
-
Insert the Get Element Value command into the script.
- In the Selector type input parameter, select the
Cssoption. - In the Element CSS input parameter, insert the value
body > div > div.center > div > div.innercontainer > div.inneritem1. - In the Timeout input parameter, insert the value
00:01:00. - In the Value output parameter, insert the value
companyData.
- In the Selector type input parameter, select the
-
Insert the Write to File command in the script.
- In the Content input parameter, insert the variable
${companyData}. - In the File path input parameter, insert the value
${directoryObtainedFiles}\text-data-company.txt. - In the Encoding input parameter, select the
Operating system defaultoption. - Enable the Overwrite input parameter.
- In the Content input parameter, insert the variable
-
Insert the Get Image from the Web command in the script.
- In the Selector type input parameter, select the
Cssoption. - In the Image CSS input parameter, insert the value
body > div > div.center > div > div.innercontainer > div.inneritem2 > img. - In the Timeout input parameter, insert the value
00:01:00. - In the Image output parameter, insert the value
graphCompany.
- In the Selector type input parameter, select the
-
Insert the Save Image command into the script.
- In the Image input parameter, insert the variable
${graphCompany}. - In the Directory input parameter, insert the variable
${directoryObtainedFiles}. - In the File name input parameter, insert the value
company-graph. - Enable the Overwrite input parameter.
- In the Image format input parameter, select the
Pngoption.
- In the Image input parameter, insert the variable
The Close browser command ends the navigation process on the web page.
What to do next
Run the script in IBM RPA Studio by clicking Start on the Home tab.