basup Posted January 28, 2010 Share Posted January 28, 2010 I am writing a script that opens a particular web page and clicks on a link in that page itself. Now, suppose for some reason "The page cannot be displayed" I want the script to generate an error message. But somehow in my script, even if the page doesnt open, It proceed to open the link(and obviosly fails). Please help.#include <IE.au3>$oIE = _IECreate()_IENavigate($oIE, "http://www.google.com")$err = @errorIf $err = 0 Then MsgBox(0, "Page1" , "Success!" & $err) _IELinkClickByText ($oIE, "Orkut") $err1 = @error If $err1 = 0 Then MsgBox(0, "Page2" , "Success!" & $err1) Else MsgBox(0, "Page2" , "Failure!" & $err1) EndIfElse MsgBox(0, "Page1" , "Failure!" & $err)EndIf Suppose I cant access google, then it should not proceed to open Orkut. But it does. Cant figure out where I am going wrong. Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 28, 2010 Share Posted January 28, 2010 When IE "fails" it then successfully loads a local page to tell you about the failure (i.e. DNS error page). You should be testing for a known element on the target page, like a certain form name, or the expected title. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
FaT3oYCG Posted January 28, 2010 Share Posted January 28, 2010 (edited) O_o you are setting the @error twice which I'm pretty sure wont return the second time and you are also using yourif else and endif's wrong from the looks of it. You could always check for the error first instead of success. Edited January 28, 2010 by FaT3oYCG Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right. Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 28, 2010 Share Posted January 28, 2010 O_o you are setting the @error twice which I'm pretty sure wont return the second time and you are also using yourif else and endif's wrong from the looks of it. You could always check for the error first instead of success.Where is he setting something twice? Where is the If\Else\EndIf wrong? Check the error first before what?What are you talking about? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
FaT3oYCG Posted January 28, 2010 Share Posted January 28, 2010 (edited) Sorry my mistake I read $err as the same as $err1 and the bad formatting also did not help, I retract my previous comments. Formatted: #include <IE.au3> $oIE = _IECreate() _IENavigate($oIE, "http://www.google.com") $err = @error If $err = 0 Then MsgBox(0, "Page1" , "Success!" & $err) _IELinkClickByText ($oIE, "Orkut") $err1 = @error If $err1 = 0 Then MsgBox(0, "Page2" , "Success!" & $err1) Else MsgBox(0, "Page2" , "Failure!" & $err1) EndIf Else MsgBox(0, "Page1" , "Failure!" & $err) EndIf p.s. it was when i posted it but the code box seems to remove the tabs o_O. Edited January 28, 2010 by FaT3oYCG Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right. Link to comment Share on other sites More sharing options...
JohnOne Posted January 28, 2010 Share Posted January 28, 2010 (edited) I think your code will click link regardkless of @error try this #include <IE.au3> $oIE = _IECreate() _IENavigate($oIE, "http://www.google.com") $err = @error If $err = 0 Then MsgBox(0, "Page1", "Success!" & $err) _IELinkClickByText($oIE, "Orkut") EndIf $err1 = @error If $err1 = 0 Then MsgBox(0, "Page2", "Success!" & $err1) ElseIf Not $err1 = 0 Then MsgBox(0, "Page2", "Failure!" & $err1) Else MsgBox(0, "Page1", "Failure!" & $err) EndIf Edited January 28, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 28, 2010 Share Posted January 28, 2010 You're missing the point. @error is not set, because IE doesn't report an error even when the page doesn't load. Try this: #include <IE.au3> $oIE = _IECreate() _IENavigate($oIE, "http://NoSuchSite.NoSuchDomain.tld") $err = @error $ext = @extended ConsoleWrite("Debug: $err = " & $err & "; $ext = " & $ext & @LF) That will fail to resolve the funky URL and IE will load its default error page instead. But because the error page loads correctly, IE is happy to report complete success and @error = 0. The point is not to trust @error at all for verifying the page you wanted got loaded. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
FaT3oYCG Posted January 28, 2010 Share Posted January 28, 2010 Could you simply check the URL after the page has loaded, if it is not the page url then it didnt load? Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now