Jump to content

Recognise error while trying to open a web page


basup
 Share

Recommended Posts

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 = @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

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

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.

:D

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

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 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

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?

:D

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

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 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

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 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

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.

:D

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

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

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...