Sign in to follow this  
Followers 0
Rico509

Problem with If...Then logic

5 posts in this topic

Hi, I'm trying to create a script that will simulate a person taking a test so I can stress test our servers and the test admin software we use without having to hire 750 temps. I already have a script using MouseClick and that works just fine, but I want to refine it so that the script can be used with any of our tests and not just ones that I've spent the time mapping out the answer options.

The new script uses PixelSearch to see if there is an answer on the page by looking for a dark blue color, if it cannot locate that color then it clicks the forward button to take it to the next screen, then starts the search again for the dark blue color.

What it does is sometimes clicks the forward button multiple times even though there are answers options on the screen. I think this has to do with how I setup the If...Then logic.

Thanks in advance for any help.

WinActivate ("PresentationDisplay")
Sleep (Random (1000, 3000, 1))
Local $i = 0
Do
  
Local $coord = PixelSearch (237, 75, 1900, 1000, 0x003399 ) ;checks to see if there is an answer option
If $coord = False Then
Local $coord = PixelSearch (0, 0, 1920, 1080, 0x10C420 ) ;green color on forward
MouseClick ("left", $coord[0], $coord[1], 1, 10)
Sleep (3000)
ElseIf $coord = True Then
   ;checks for option A
Local $coord = PixelSearch (222, 55, 1900, 1000, 0x003399 ) ;blue color around answers
Local $random
$random = Random (1, 4, 1)
   If $random = 1 Then
   MouseClick ("left", $coord[0], $coord[1], 1, 10) ;clicks A
   Call ("Sleep1")
   ElseIf $random = 2 Then
   MouseClick ("left", $coord[0], $coord[1] + 30, 1, 10) ;clicks B
   Call ("Sleep1")
   ElseIf $random = 3 Then
   MouseClick ("left", $coord[0], $coord[1] + 60, 1, 10) ;clicks C
   Call ("Sleep1")  
   ElseIf $random = 3 Then
   MouseClick ("left", $coord[0], $coord[1] + 90, 1, 10) ;clicks D
   Call ("Sleep1")
   EndIf
   Local $coord = PixelSearch (0, 0, 1920, 1080, 0x10C420 ) ;clicks forward
   MouseClick ("left", $coord[0], $coord[1], 1, 10)
   Call ("Sleep1")
   If WinExists ("Blocking Question") Then
   Call ("Sleep1")
   Local $coord = PixelSearch (740, 337, 1181, 726, 0x3C7FB1 )
   MouseClick ("left", $coord[0], $coord[1], 1, 10)
   Call ("Sleep1")
   EndIf
EndIf
$i = $i + 1
Until $i = 45

Share this post


Link to post
Share on other sites



sounds like you need a stress test tool, rather than an automation tool


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

I was thinking of rewriting your code, replacing all the If's after setting $random with a Switch..EndSwitch statement, when I noticed that you're checking If $random = 3 twice. Maybe that's the issue here.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

jdelaney - I whole heartedly agree with you.

somdcomputerguy and JohnOne - well that most certainly could be the issue, that second 3 should be a 4. Idiot mistake on my part, I'll replace it and see if that fixes it. Thank you very much.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0