Answered

How to execute a while loop

I'm trying to click an element but want to wait as long as another element is present.

How can we do this in Subject7? 

Example: While (spinner = exist) { wait}

 

0
5 comments
Avatar
Joseph Hamdan

Hi Hasib,

This can be done using a combination of If, Loop and Get_Web_Value (With CSS type and 'visibility' attribute). For example:

 

Set_Var HALT Static count "0" #variable for tracking count in order not to make infinite cycle

Loop HALT index 1 5 1

-Get_Web_Value HALT variable LOCATOR locator_name CSS false #This step gets the current visibility value

-If HALT TEXT variable = visible #This step compares variable value from above step with 'visible'. If the object is visible, the following 'Wait' step will execute.

-Wait HALT 'seconds'

-Else HALT

-Loop_Break HALT

-End_If HALT

-Set_Var HALT Expression index "@index-1"

-Set_Var HALT Expression count “@count-1"  #cycle count steps
-If HALT NUMBER count > 1000 #cycle count steps(adjust number to your preference)
-Loop_Break HALT #cycle count steps
-End_If HALT #cycle count steps

-Loop_End HALT

 

Regards,

Subject7 Team

0
Comment actions Permalink
Avatar
Hasib Rostaiee

Thank you,

Can you describe below steps:

-Set_Var HALT Expression count “@count-1"  #cycle count steps
-If HALT NUMBER count > 1000 #cycle count steps(adjust number to your preference)

Why are decreasing count? In that case, it will never match the condition count>1000 or even count>1;

 

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi Hasib,

Sorry, this was a typo. It should be:

-Set_Var HALT Expression count “@count+1"  #cycle count steps

Regards,

Subject7 Team

0
Comment actions Permalink
Avatar
Hasib Rostaiee

Thank you, what about "-Set_Var HALT Expression index "@index-1", what is the purpose of this step? is to reset the loop back to 0?

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi Hasib,

This is to make loop infinite up to the element is visible or counts is reached.

Regards,

Subject7 Team

0
Comment actions Permalink

Please sign in to leave a comment.