Definition
"IF statement" is used to determine whether a given condition is met. It decides to execute one of two specified operations based on the outcome- true or false. A high-quality workflow certainly includes a significant number of IF statements.
If
First, let's take a look at the "If" command.
The "if" condition is used for conditional judgments between 2 variables, expressions, texts, or numbers to determine the direction of the workflow. There are various conditions for judgment, such as equals to, not equals to, greater than, less than, contains, does not contain, etc.
If - multiple conditions
Let's move on to the If - multiple conditions.
It can set multiple conditions to determine whether to execute certain commands. We can choose match criteria between Match all conditions and Match any of the conditions. We can set only one condition or add more than one condition on demand.
Let's say we set 10 greater than 5 as the first condition and 10 less than 20 as the second condition. Then click run to check the logs. We can see that the result is true and the following command "Display toast" is executed successfully.
If we change the 20 to 9 for the second condition, making it 10 less than 9, which is logically wrong, then the If - multiple conditions command is false because even though the first condition 10 greater than 5 is met, the second condition 10 less than 9 remains false and the match criteria is Match all. Therefore, the following command "Display toast" is not executed.
If webpage contains
Next, let's jump to the "If webpage contains" command, which is used to check whether a specified text or element appears on a webpage. Its parameters include the target webpage and 4 types of conditions: Element is found, Element is not found, Text is found and, Text is not found. For details, please check out the tutorial [Command] If web page contains.
For instance, let's use the Go to web page command to enter a webpage (www.google.com) with Octoparse RPA built-in browser, and save the web page as a variable named Google_Page.
Double-click or drag and drop the command "If webpage contains", choose the "Google_Page" generated from the Go to webpage command, and select Element is found for the second parameter Check if.
Click +Capture to jump to the Google_Page to select an element to check if the specific element is found, and move the cursor over "Google Search" button, and press "Ctrl+left click with the mouse" to locate the target element.
Similarly, we can add a "Display toast" command to verify the execution status of the"If webpage contains" command.
As a result, the Google Search button is found on the webpage indeed and the If webpage contains and the Display toast commands are executed successfully again.
That's all about today's lesson. For more specific tutorials, please go to the If command section.
โ