Sign in to follow this  
Followers 0
caseybrown89

Need help with script that opens IE and navigates

5 posts in this topic

I'm trying to write a script that opens IE, navigates to google, then navigates to a URL specified by a command line parameter.

The issue that I'm having is that I'm trying to return an error code and close the browser if the path specified in the command line is invalid. What I believe is actually happening is that the script is not terminating because the error window in IE is displayed. After that, I get an error from AutoIt as well.

Any help would be appreciated, the code is listed below.

Thanks,

Casey

#include <WinAPI.au3>
#include <IE.au3>

;; Get the desired path to the URL
$path = $CmdLine[1]

;; Not sure if I need this.
_IEErrorNotify(False)

;; Launch a browser, navigate to google, and wait for the screen to load.
$browser = _IECreate ("http://www.google.com", 0, 1, 1, 1)

;; Navigate to the path given in the command line
_IENavigate ($browser, $path , 0)

;; Wait for error message to appear if Path is invalid.
sleep(1000)

;; If the error message window appears
if (WinExists("[CLASS:#32770]")=1) Then
    _IEQuit($browser)
    Exit (1)
EndIf

;; Otherwise, exit with success.
Exit

Share this post


Link to post
Share on other sites



Have you tried using WinClose instead of IEquit?

Might solve the problem.

-1


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

Have you tried using WinClose instead of IEquit?

Might solve the problem.

-1

Well I switched out _IEQuit for WinClose and that doesn't seem to do the trick. I think the main issue is that when _IENavigate attempts to navigate to an invalid URL, my script becomes suspended. I can't seem to get AutoIt to handle the error message for the invalid URL and I'm not sure why.

Share this post


Link to post
Share on other sites

bump.

The problem is that _IENavigate creates an error message that is system modal (at least I think).

I'm now attempting to manually enter the command line URL into the address bar and navigate by hitting enter.

I have the following code written, but the text is not input into the address bar.

#include <WinAPI.au3>
#include <IE.au3>

;; Get the desired path to the URL
$path = $CmdLine[1]

;; Not sure if I need this.
_IEErrorNotify(False)

;; Launch a browser, navigate to google, and wait for the screen to load.
$browser = _IECreate ("http://www.google.com/", 0, 1, 1, 1)

;; Ensure the window is active
WinActivate("Google - Windows Internet Explorer")

MsgBox(4096, "1", "text should be entered after this")

;Manually entering URL
ControlFocus("Google - Windows Internet Explorer", "", "[CLASS:ToolbarWindow32; INSTANCE:2]")
Send("^a" + $path) 


;; Search children windows
Opt("WinSearchChildren", 1)  

;; If the error message window appears
if (WinExists("[TITLE:Windows Internet Explorer; CLASS:Button; INSTANCE:1]")) Then
    ;; Exact Match of Title
    MsgBox(4096, "1", "the URL is wrong")
    Opt("WinTitleMatchMode", 2)
    WinClose("Google - Windows Internet Explorer", "")
    ;_IEQuit($browser)
    Exit (1)
EndIf

;; Otherwise, exit with success.
MsgBox(4096, "1", "the URL is correct")
Exit

Share this post


Link to post
Share on other sites

Well I switched out _IEQuit for WinClose and that doesn't seem to do the trick. I think the main issue is that when _IENavigate attempts to navigate to an invalid URL, my script becomes suspended. I can't seem to get AutoIt to handle the error message for the invalid URL and I'm not sure why.

I figured out the issue, here is the code for reference in the future if anyone searches the forum. Mod - this thread can be closed.

#include <WinAPI.au3>
#include <IE.au3>

;; Get the desired path to the URL
$path = $CmdLine[1]

;; Not sure if I need this.
_IEErrorNotify(False)

;; Launch a browser, navigate to google, and wait for the screen to load.
$browser = _IECreate ("http://www.google.com/", 0, 1, 1, 1)

;; Focus in on window
WinActivate("Google - Windows Internet Explorer")

;Manually entering URL
ControlFocus("Google - Windows Internet Explorer", "", "[CLASS:ToolbarWindow32; INSTANCE:2]")
Send("^a" & " " & $path & "{ENTER}") 

sleep(1000)

;; Search children windows
Opt("WinSearchChildren", 1)

;; If the error message window appears
if (WinExists("Address Bar", "Windows cannot find")) Then
    ;; Exact Match of Title
    send("{Enter}")
    Opt("WinTitleMatchMode", 2)
    WinClose("Google - Windows Internet Explorer", "")
    ;_IEQuit($browser)
    Exit (1)
EndIf

;; Otherwise, exit with success.
;; Let the application load
sleep(5000)
Exit

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