Jump to content

trying to write script for if....then but stuck


fst
 Share

Recommended Posts

hello all.  I'm new to the site as well as to using and hoping to fully understand and grasp the AutoIT software.  currently i have a temporary, working, script but it's stuck on an infinite loop even though i had thought i had it working to stop at a specific number.  furthermore, i am trying to write an if...then  or if.....else(if) whena different action occurs.   heres the scenario:

i have a webpage (sharepoint) where i am doing a certain number of mouse clicks to select data and then deleting them.  each time the page refreshes and the loop continues.  at times, the network may get busy so the page times out and gets the "This page can’t be displayed", where if i refresh (F5) the page works again. 

well, heres what i have currently, in advance much appreciated for everyone's help:

 

#region --- Internal functions Au3Recorder Start ---
Func _Au3RecordSetup()
Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '')
If $aResult[1] <> '00000409' Then
  MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & @CRLF & '(00000409->' & $aResult[1] & ')')
EndIf

EndFunc

Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)

    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc

_AU3RecordSetup()
#endregion --- Internal functions Au3Recorder End ---
Global $x = 1
Do
   If _WinWaitActivate("Recycle Bin - Internet Explorer","") = _WinWaitActivate("Recycle Bin - Internet Explorer","") Then
      Sleep(3000)
MouseClick("left",1070,295,1)
Sleep(3700)
MouseClick("left",155,300,1)
Sleep(2300)
MouseClick("left",305,249,1)
Sleep(2000)
_WinWaitActivate("Message from webpage","")
Sleep(500)
Send("{ENTER}")
Sleep(1000)
Sleep(10000)
ElseIf   _WinWaitActivate("This page can’t be displayed - Internet Explorer","") = _WinWaitActivate("This page can’t be displayed - Internet Explorer","") Then
   Send("{F5}")
_WinWaitActivate("Recycle Bin - Internet Explorer","")
Sleep(10000)
MouseClick("left",1070,295,1)
Sleep(3700)
MouseClick("left",155,300,1)
Sleep(2300)
MouseClick("left",305,249,1)
Sleep(2000)
_WinWaitActivate("Message from webpage","")
Sleep(500)
Send("{ENTER}")
Sleep(1000)
Sleep(10000)
EndIf
Until $x = 3

#endregion --- Au3Recorder generated code End ---

 

Link to comment
Share on other sites

You never increment, or change in any way, the $x variable, so it's never going to equal 3, so the Do loop never ends.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

No, you can use the Do loop, you just need to somehow make the $x variable equal 3 at some point. Either increment it by one each time through the loop (if you only want it to run 3 times) or set it to 3 sometime during your run.

The best way to accomplish looping three times would be to use a For/Next loop though.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Open the help file, search for For in it, and run the example script that you'll find in the function description.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

ok i managed to remove the Do...Until and using the For...Next.  However whenever the webpage times out after 15 minutes or so the "This page can’t be displayed - Internet Explorer" shows up.  I am trying to have the script refresh the page when that happens but it's not working.

 

#region --- Au3Recorder generated code Start (v3.3.9.5 KeyboardLayout=00000409)  ---

#region --- Internal functions Au3Recorder Start ---
Func _Au3RecordSetup()
Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '')
If $aResult[1] <> '00000409' Then
  MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & @CRLF & '(00000409->' & $aResult[1] & ')')
EndIf

EndFunc

Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)

    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc

_AU3RecordSetup()
#endregion --- Internal functions Au3Recorder End ---
For $i = 1 To 20 Step +1

   If _WinWaitActivate("Recycle Bin - Internet Explorer","") = _WinWaitActivate("Recycle Bin - Internet Explorer","") Then
      Sleep(3000)
MouseClick("left",1070,295,1)
Sleep(3700)
MouseClick("left",155,300,1)
Sleep(2300)
MouseClick("left",305,249,1)
Sleep(2000)
_WinWaitActivate("Message from webpage","")
Sleep(500)
Send("{ENTER}")
Sleep(1000)
Sleep(10000)
ElseIf  _WinWaitActivate("This page can’t be displayed - Internet Explorer","") = _WinWaitActivate("This page can’t be displayed - Internet Explorer","") Then
   Send("{F5}")
_WinWaitActivate("Recycle Bin - Internet Explorer","")
Sleep(10000)
MouseClick("left",1070,295,1)
Sleep(3700)
MouseClick("left",155,300,1)
Sleep(2300)
MouseClick("left",305,249,1)
Sleep(2000)
_WinWaitActivate("Message from webpage","")
Sleep(500)
Send("{ENTER}")
Sleep(1000)
Sleep(10000)
EndIf
Next

 

I'm thinking im using the incorrect WinWaitActivate and maybe use the IExxxx instead?   or maybe after the ElseIf adding the Not and have the line as:

ElseIf Not _WinWaitActivate("Recycle Bin - Internet Explorer","") Then

 

Edited by fst
edit
Link to comment
Share on other sites

If you are using IE, why don't you bind to the IE object and fire off a $oIE.refresh command? That might work (firing f5 might fail if you are on a different window or something)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...