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:

  1. Insert the Get System Folder Path command into the script.

    1. In the Folder input parameter, select the My Documents option.
    2. In the Path output parameter, insert the value pathMyDocuments.
  2. Insert the Create Directory command in the script.

    1. In the Path input parameter, insert the value ${pathMyDocuments}\rpa_challenge_tutorial.
    2. In the Directory output parameter, insert the value directoryObtainedFiles.

    Starting the browser

    Insert the commands to create a new instance of the browser:

  3. In the Home tab, click the New variable button to define a new variable.

    1. In the Name input parameter, insert the value instanceName.
    2. In the Variable Type input parameter, select the Text option.
    3. In the Value input parameter, insert the value browser-instance.
  4. Insert the Start Browser command into the script.

    1. In the Instance name input parameter, insert the variable ${instanceName}.
    2. 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.

  5. In the Close Browser command, insert the values:

    1. In the Instance name input parameter, insert the variable ${instanceName}.
    2. 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 External link web page:

  6. Insert the Navigate command into the script.

    1. 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:

  7. Insert the Wait for Web Page Requests command in the script.

    1. 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:

  8. Insert the Get Web Table command into the script.

    1. In the Selector Type input parameter, select the Css option.
    2. In the CSS input parameter, insert the value body > div > div.center > div > div.items > table.
    3. In the Timeout input parameter, insert the value 00:00:30.
    4. 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.

  9. In the Home tab, click the New variable button to define a new variable.

    1. In the Name input parameter, insert the value pathCsvFile.
    2. In the Variable Type input parameter, select the Text option.
  10. Insert the Assign Variable command in the script.

    1. In the Variable input parameter, insert the variable ${pathCsvFile}.
    2. In the Value input parameter, insert the value ${directoryObtainedFiles}\rates-per-country.csv.
  11. Insert the Write Table to File command in the script.

    1. Enable the Add Header input parameter.
    2. In the Data Table input parameter, insert the variable ${ratesForCountries}.
    3. In the From Row input parameter, insert the value 1.
    4. In the Delimiter input parameter, select the value By Characters.
    5. In the Separator input parameter, insert the value ,.
    6. 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.

  12. Insert the Select Item in Combo Box command in the script.

    1. In the Search by input parameter, select the Id option.
    2. In the ID input parameter, insert the value country.
    3. In the Select Option by input parameter, select the option Value.
    4. In the Value to Select input parameter, insert the value "WEX Academy Inc.".
    5. In the Timeout input parameter, insert the value 00:01:00.
  13. Insert the Click on Web Page command in the script.

    1. In the Search for input parameter, select the Css option.
    2. In the CSS input parameter, insert the value body > div > div.center > div > div.innercontainer > div.navbar2 > p > input[type=image].
    3. 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.

  14. Insert the Get Element Value command into the script.

    1. In the Selector type input parameter, select the Css option.
    2. In the Element CSS input parameter, insert the value body > div > div.center > div > div.innercontainer > div.inneritem1.
    3. In the Timeout input parameter, insert the value 00:01:00.
    4. In the Value output parameter, insert the value companyData.
  15. Insert the Write to File command in the script.

    1. In the Content input parameter, insert the variable ${companyData}.
    2. In the File path input parameter, insert the value ${directoryObtainedFiles}\text-data-company.txt.
    3. In the Encoding input parameter, select the Operating system default option.
    4. Enable the Overwrite input parameter.
  16. Insert the Get Image from the Web command in the script.

    1. In the Selector type input parameter, select the Css option.
    2. In the Image CSS input parameter, insert the value body > div > div.center > div > div.innercontainer > div.inneritem2 > img.
    3. In the Timeout input parameter, insert the value 00:01:00.
    4. In the Image output parameter, insert the value graphCompany.
  17. Insert the Save Image command into the script.

    1. In the Image input parameter, insert the variable ${graphCompany}.
    2. In the Directory input parameter, insert the variable ${directoryObtainedFiles}.
    3. In the File name input parameter, insert the value company-graph.
    4. Enable the Overwrite input parameter.
    5. In the Image format input parameter, select the Png option.

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.