Skip to content

IF Condition

Naibo Wang edited this page Feb 23, 2023 · 4 revisions

We can define the If Condition to set different branch to execute the workflow.

Define Operation (at the Task Design stage)

To define the If Condition, we need to use the Toolkit on the Workflow Manager.

Only two steps to add the IF Condition to the workflow:

  1. Click the "If Condition" button at the toolkit.

  2. Click the anchor where you want to insert the "IF Condition".

image

Then the "If Condition" operation will be inserted to the workflow at the anchor.

image

We can see that the If Condition has at least two "Condition" operations, and we can add, delete or copy any "condition" operation based on our requirements.

Add Condition

To add additional condition, click the "Click here to add a new condition to the left most" link to add a new condition operation:

image

Then an additional condition operation will be added to the left most:

image

Execution Rules

When executing tasks, EasySpider will first check the condition defined in the first (left most) "Condition" operation, if meet, then run operations inside the first operation; otherwise, EasySpider will check the condition defined in the second (from left to right, top to down) condition, if meet, then run operations inside the second operation, and so on.

Operation Properties

For the "IF Condition" operation:

  • Option Name: the option name, click the "Confirm" button to refresh the name after modification.

  • Seconds after executed: how long should EasySpider wait after automatically finished the whole IF condition.

For the "Condition" operation:

  • Option Name: the option name, click the "Confirm" button to refresh the name after modification.

  • Condition Type: What kind of condition should be meet in order to execute operations inside this "Condition" operation.

  • Text/Xpath of Element: parameters of the condition, e.g., if the condition type is "Text inside current page", then we will need to set the text we want to find inside this "Text/Xpath of Element" textbox.

  • Seconds after executed: how long should EasySpider wait after automatically finished current condition operation.

Example Case

For example, we defined 4 "Condition" operations inside an "If Condition" operation:

image

Conditions defined in the four conditions are:

  1. Condition1: Text inside current page, text is "Computer".

image

  1. Condition2: Element inside current page, Xpath of element is "//span/a".

image

  1. Condition3: Text inside current loop, text is "PC".

  2. Condition4: No Condition.

Then EasySpider will:

  1. Check the condition defined in "Condition1" operation, i.e., whether text "Computer" exists in the current opened web page, if yes, execute "Input Text" operation defined inside the "Condition1" operation. If text "Computer" does not exist in the current opened web page, go to step 2.

  2. Check the condition defined in "Condition2" operation, i.e., whether element with XPath "//span/a" exists in the current opened web page, if yes, execute "Collect Data" operation defined inside the "Condition2" operation. Otherwise, go to step 3.

  3. Check the condition defined in "Condition3" operation, i.e., if the "If Condition" operation is inside a "Loop" condition, then check whether text "PC" exists in the element(s) defined in the "Loop" operation, if yes, execute "Click Element" operation defined inside the "Condition3" operation. Otherwise, go to step 4.

  4. Check the condition defined in "Condition4" operation, here is "No condition", which means no need any requirement to execute it. Since no operation is defined inside this "Condition4" operation, thus nothing will be executed.

Clone this wiki locally