Jump to content

IE script failing while in GUI


Recommended Posts

I have a login script that extracts some data, but when I put it in as a function when you click a button in the GUI it skips all the steps until it gets to the extract and then crashes saying the element doesn't exist (which it doesn't because I'm not logged in)

This is what I have:

Local $oIE, $GUI_Button_Back, $GUI_Button_Forward
    Local $GUI_Button_Home, $GUI_Button_Stop, $msg

    $oIE = ObjCreate("Shell.Explorer.2")

    ; Create a simple GUI for our output
    GUICreate("TEST",1050,600,(@DesktopWidth-1050)/2,(@DesktopHeight-600)/2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
    GUICtrlCreateObj($oIE, 5, 5, 1045, 550)
    $GUI_Button_Extract = GUICtrlCreateButton("Extract", 700, 565, 100, 30)
Case $msg = $GUI_Button_Extract
                ; Get pointers to the login form and username and password fields
                $oIE.navigate("https://localhost:1234/login")
                $o_form = _IEFormGetObjByName($oIE, "loginForm")
                $o_login = _IEFormElementGetObjByName($o_form, "userId")
                $o_password = _IEFormElementGetObjByName($o_form, "password")
                ; Set field values and submit the form
                _IEFormElementSetValue($o_login, $saved_un1)
                _IEFormElementSetValue($o_password, $saved_pw1)
                _IEFormSubmit($o_form)

When I run the script as a stand alone, it functions without any issues. How can I fix this?

Edited by Jewtus
Link to comment
Share on other sites

You are reliant upon the IE object you create at the beginning of the scirpt...are you closing the browser at any point prior to clicking on the button?

You can always insert failure handling.  Check if isobj() on $oIE, or create a new one.

^ Just speculative.

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.
Link to comment
Share on other sites

I don't close the IE window or anything weird. I do have a close event on another button, but that shouldn't be an issue. I did have

_IENavigate($oIE, "https://localhost:1234/login")

before and I had to change it to 

$oIE.navigate("https://localhost:1234/login")

to get it to actually navigate to the page.

Any chance this is an issue with invoking it in Shell.Explorer.2

Link to comment
Share on other sites

I'm trying to have the IE window inside the GUI. When I use _IECreate, it pops up a new window. Worst case scenario, I can have this stuff run in a window and just have it process in the background, but ideally, I'd like it to show up in the GUI.

I found this link that has the syntax for shell.explorer.2, but I don't know if I can still execute the _IE UDFs inside a shell...

http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx

Edited by Jewtus
Link to comment
Share on other sites

Yes, and it doesn't work.

In order to get the IE window into the GUI (as far as I can tell from several examples) is to create the shell explorer object. This apparently slims down some of the features available in IE as well, which might explain why the other commands are failing. I think I might need a modded IE.au3 to get this working properly...

Link to comment
Share on other sites

Yes, and it doesn't work.

In order to get the IE window into the GUI (as far as I can tell from several examples) is to create the shell explorer object. This apparently slims down some of the features available in IE as well, which might explain why the other commands are failing. I think I might need a modded IE.au3 to get this working properly...

What is not working? I've embedded IE pages into several GUIs. What are you expecting to see or have happen?

Link to comment
Share on other sites

Well

Local $oIE, $GUI_Button_Back, $GUI_Button_Forward
    Local $GUI_Button_Home, $GUI_Button_Stop, $msg

    $oIE = ObjCreate("Shell.Explorer.2")

    ; Create a simple GUI for our output
    GUICreate("TEST",1050,600,(@DesktopWidth-1050)/2,(@DesktopHeight-600)/2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
    GUICtrlCreateObj($oIE, 5, 5, 1045, 550)
    $GUI_Button_Extract = GUICtrlCreateButton("Extract", 700, 565, 100, 30)

Creates the GUI with an embedded IE window (via shell.explorer)

Case $msg = $GUI_Button_Extract
                ; Get pointers to the login form and username and password fields
                $oIE.navigate("https://localhost:1234/login")
                $o_form = _IEFormGetObjByName($oIE, "loginForm")
                $o_login = _IEFormElementGetObjByName($o_form, "userId")
                $o_password = _IEFormElementGetObjByName($o_form, "password")
                ; Set field values and submit the form
                _IEFormElementSetValue($o_login, $saved_un1)
                _IEFormElementSetValue($o_password, $saved_pw1)
                _IEFormSubmit($o_form)

This part should navigate the embedded page to a form, identify the elements, fill out the form, and then submit the form. I put a msgbox in to see what steps were failing and every single UDF call does nothing. The $oIE.Navigate command does work because its using the syntax for Shell.explorer.2 (basically it navigates to the page and immediately pops up the msg box). If I use IE create and run this, it works without incident but it works OUTSIDE the GUI. It appears that inside the GUI, you cannot execute the UDF commands, unless there is another way to embed the IE page inside the GUI that I'm overlooking...

 

EDIT: Also IE.Navigate doesn't wait for the window to load and when you try to use IE.NavigateComplete it doesn't navigate.

Edited by Jewtus
Link to comment
Share on other sites

Are you using the IE udf?

#include <ie.au3>
Local $oIE, $GUI_Button_Back, $GUI_Button_Forward
    Local $GUI_Button_Home, $GUI_Button_Stop, $msg

    $oIE = _IECreateEmbedded()

    ; Create a simple GUI for our output
    GUICreate("TEST",1050,600,(@DesktopWidth-1050)/2,(@DesktopHeight-600)/2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
    GUICtrlCreateObj($oIE, 5, 5, 1045, 550)
    $GUI_Button_Extract = GUICtrlCreateButton("Extract", 700, 565, 100, 30)

GUISetState() ;Show GUI

_IENavigate($oIE, "http://www.autoitscript.com")

While 1
    Local $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
EndSelect
WEnd
Link to comment
Share on other sites

I've been messing around with different websites and the embedded seems to work on some sites, but not on others. At this point, I think I'm just going to make it run in the background. I have a feeling the issue is with some of the security things that are preloaded in the template I'm using for my report.

I tried the other stuff you all mentioned against Google and facebook, and it works like a charm, but not against my localhost report. Weird.

PS, I did debug it for a few hours and nothing is showing any errors, its just not operating properly.... weird..

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