Create Order Process
To get things started, you need to implement a function for opening the robot order website. Here's a draft for the function. You need to add the implementation (calling functions to accomplish things):
Visual Studio Code: You can place the function definitions either before or after the
@taskannotated function. The order does not matter.
- You need a library that knows how to work with a web browser.
- We recommend using the browser module of the robocorp library for this course.
- After importing the library, call the function for opening the browser. You might need to provide the URL of the robot order website!
When you get the robot order website to open in a web browser, you can proceed to the next step!
- The orders CSV file is here: https://robotsparebinindustries.com/orders.csv
- You need another module from the robocorp library for downloading things.
- You want to overwrite the downloaded file if it exists to be able to run your robot over and over again. There is an argument for telling that overwriting is ok!
- There is an RPA Framework library for reading CSV files into
tablesthat can then be looped in a robot script. Sometimes, the
Readmeof the library contains all the information we need 😉.
All RPA Framework libraries can be used with Python as well. Check out the examples from each library to get a better idea.
- You need your custom
get_orders()function to return the result. Check out returning things from a function.
- Learn about assigning variables to assign the returned orders to a variable.
You can check if your code works from the log after you run your robot.
You need to complete the ordering process for each of the orders.
- You need to use a for loop.
- For now, you can just log each order row inside the loop.
Time to get rid of that annoying modal that pops up when you open the robot order website.
Let's implement the
- You have already imported the library you need.
- Functions that click on things might prove useful here.
- The "click on stuff" function needs a locator so that they know what to click on. Locators are the bread and butter of automating web applications. It is good to spend some time reading about those.
- You can use the browser inspector tools to find the elements to click on.
- You can target HTML elements either with CSS type, class, ID, or attribute selectors or XPath expressions, or a combination of CSS, XPath, and text selectors.
Time to tackle the
fill_the_form() function. This example function takes an argument.
- Use the order row that you got from the loop you built as the argument for this form filler function.
- If the name of the variable you got from the loop is, for example,
row, you can access the value of the
Order numbercolumn like this:
- You need functions for selecting things and inputting text. You have a library you need already imported!
- The input element for the leg number is slightly annoying. It does have an
idattribute, but the value seems to change all the time! 🤬 Can you think of a way of targeting that element? There are no "correct" answers here, just many options!
To robotically get the image of the robot, the robot needs to preview the robot (Yo Dawg!).
- Click on stuff. Business as usual!
This one is a bit trickier case. Sometimes the submit fails. We really want the robot to complete the orders even when there are occasional errors on submit. How do we do that? 🤔
- When it fails, an error message is displayed on the screen.
- If there is an error, you just have to click order again and hope it works.