Sign in to follow this  
Followers 0
quacky

_IECreateEmbedded() and Javascript popup (hang)

10 posts in this topic

I need to automate login to a website. I can do it just fine by using _IECreate(), and when the login prompt appears, the script recognizes the new window and send the appropriate login/password (included demo values won't login).

However, when opening the site through _IECreateEmbedded() in a GUI (preferred way!), I get stuck on _IENavigate. It looks like the script is waiting for the page to load, but the Javascript prompt is hanging it up. Any ideas? Thanks in advance.

#include <IE.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

;hotkey
HotKeySet("{ESC}", "Terminate")

$url = "http://ceviewv3.cygnus.com/ceview/application.htm"
$userName = "demo"
$password = "demo"

$oIE = _IECreateEmbedded()
GUICreate("test", 1024, 768, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 10, 1004, 748)

 ;Show GUI
GUISetState()

_IENavigate($oIE, $url, 0)

;wait for login popup
WinWait("ceView Logon")

;get login window handle
$login = WinGetHandle("ceView Logon")

;send username, password, and submit
ControlSend($login, "", "[CLASS:ATL:Eon00031; INSTANCE:1]", $userName)
ControlSend($login, "", "[CLASS:ATL:Eon00031; INSTANCE:2]", $password)
Sleep(500)
ControlClick($login, "", "[CLASS:ATL:Eon00004; INSTANCE:1]", "left", 1)

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I guess your script is blocked because of a site page's alert box or other blocking something that needs the user attention before it can move on. Example:

#include <IE.au3>

Global $oIE, $oBtn
Global $IE_Ctrl
Global $hGUI
Global $sHTML

$hGUI = GUICreate("Test", 400, 400)
$oIE = _IECreateEmbedded()
$IE_Ctrl = GUICtrlCreateObj($oIE, 0, 0, 400, 400)

GUISetState()

_IENavigate($oIE, "about:blank")
$sHTML = '<HTML><HEAD><TITLE>TITLE</TITLE></HEAD><BODY><INPUT TYPE=button VALUE="Click" ID=Btn onclick="alert('' (\\/)\n(oO)\n\(\'')(\'')'')"></BODY></HTML>'

_IEDocWriteHTML($oIE, $sHTML)

$oBtn = _IEGetObjById($oIE, "Btn")
If IsObj($oBtn) Then _IEAction($oBtn, "click")

; If alert is still visible then this MsgBox line
; won't get executed until the alert box is closed.
MsgBox(0x40, "Title", "Text")

Do
Until GUIGetMsg() = -3

GUIDelete()
Exit
Edited by Authenticity

Share this post


Link to post
Share on other sites

The second example for _IEAction shows a woraround for the issue here where control is not returned to your script after an alert.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

I think that this approach is not working with IE embedded control. You can try a few more test like using AdlibEnable(), WM_TIMER, or some other tricks. It just doesn't matter as far as I've tested, it's still blocking your script. Correct me if I've tested it incorrectly.

Share this post


Link to post
Share on other sites

I think that this approach is not working with IE embedded control. You can try a few more test like using AdlibEnable(), WM_TIMER, or some other tricks. It just doesn't matter as far as I've tested, it's still blocking your script. Correct me if I've tested it incorrectly.

Yep, hasn't worked for me either. AdlibEnable() also doesn't work... BUT I found a sloppy work around!

FIRST I must run this "login hack" script completely separately. All it does is look for the spawned login window:

While 1
    If WinExists("ceView Logon") Then
        $userName = "demo"
        $password = "demo"
        $login = WinGetHandle("ceView Logon")
        ;send username, password, and submit
        Sleep(500)
        ControlSend($login, "", "[CLASS:ATL:Eon00031; INSTANCE:1]", $userName)
        ControlSend($login, "", "[CLASS:ATL:Eon00031; INSTANCE:2]", $password)
        Sleep(500)
        ControlClick($login, "", "[CLASS:ATL:Eon00004; INSTANCE:1]", "left", 1)
        Exit
    EndIf
WEnd

SECOND I run the embed script, which now works as expected:

#include <IE.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

;hotkey
HotKeySet("{ESC}", "Terminate")

$url = "http://ceviewv3.cygnus.com/ceview/application.htm"
$userName = "demo"
$password = "demo"

GUICreate("test", 1024, 768, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$oIE = _IECreateEmbedded()
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 10, 1004, 748)

;Show GUI
GUISetState()

;open site, here's where it gets stuck on the login popup
_IENavigate($oIE, $url, 0)

While 1
    ;the "login hack" script will take care of the login popup
WEnd

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Although this is working I sill don't feel I'm approaching it correctly. I did try the other method options posted... there must be another way to do this?

Thanks everyone for your help.

Share this post


Link to post
Share on other sites

I think that this approach is not working with IE embedded control. You can try a few more test like using AdlibEnable(), WM_TIMER, or some other tricks. It just doesn't matter as far as I've tested, it's still blocking your script. Correct me if I've tested it incorrectly.

What approach are you talking about? What I suggested will work just as well in an embedded control as in a standalone browser.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#include <IE.au3>
Opt("WinSearchChildren", 1)

$oIE = _IECreateEmbedded()
$hGUI = GUICreate("Title", 400, 400)
$IE_Ctrl = GUICtrlCreateObj($oIE, 0, 0, 400, 400)

_IENavigate($oIE, "about:blank")
_IEDocWriteHTML($oIE, _IE_Form())

GUISetState()


$oSubmit = _IEGetObjByName ($oIE, "submitExample")
_IEAction ($oSubmit, "focus")
ControlSend($hGUI, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

; Wait for Alert window, then click on OK
WinWait("Windows Internet Explorer", "ExampleFormSubmitted")
ControlClick("Windows Internet Explorer", "ExampleFormSubmitted", "Button1")
MsgBox(0x40, "Title", "Text")

GUIDelete()
Exit

Func _IE_Form()
    Local $s_html = ""
    
    $s_html &= "<HTML>" & @CR
    $s_html &= "<HEAD>" & @CR
    $s_html &= "<TITLE>_IE_Example('form')</TITLE>" & @CR
    $s_html &= "<STYLE>body {font-family: Arial}</STYLE>" & @CR
    $s_html &= "</HEAD>" & @CR
    $s_html &= "<BODY>" & @CR
    $s_html &= "<form name='ExampleForm' onsubmit='javascript:alert(""ExampleFormSubmitted"");' method='post'>" & @CR
    $s_html &= "<table cellspacing=6 cellpadding=6 border=1>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>ExampleForm</td>" & @CR
    $s_html &= "<td>&lt;form name='ExampleForm' onsubmit='javascript:alert(""ExampleFormSubmitted"");' method='post'&gt;</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>Hidden Input Element<input type='hidden' name='hiddenExample' value='secret value'></td>" & @CR
    $s_html &= "<td>&lt;input type='hidden' name='hiddenExample' value='secret value'&gt;</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>" & @CR
    $s_html &= "<input type='text' name='textExample' value='http://' size='20' maxlength='30'>" & @CR
    $s_html &= "</td>" & @CR
    $s_html &= "<td>&lt;input type='text' name='textExample' value='http://' size='20' maxlength='30'&gt;</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>" & @CR
    $s_html &= "<input type='password' name='passwordExample' size='10'>" & @CR
    $s_html &= "</td>" & @CR
    $s_html &= "<td>&lt;input type='password' name='passwordExample' size='10'&gt;</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>" & @CR
    $s_html &= "<input type='file' name='fileExample'>" & @CR
    $s_html &= "</td>" & @CR
    $s_html &= "<td>&lt;input type='file' name='fileExample'&gt;</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>" & @CR
    $s_html &= "<input type='image' name='imageExample' alt='AutoIt Homepage' src='http://www.autoitscript.com/images/autoit_6_240x100.jpg'>" & @CR
    $s_html &= "</td>" & @CR
    $s_html &= "<td>&lt;input type='image' name='imageExample' alt='AutoIt Homepage' src='http://www.autoitscript.com/images/autoit_6_240x100.jpg'&gt;</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>" & @CR
    $s_html &= "<textarea name='textareaExample' rows='5' cols='15'>Hello!</textarea>" & @CR
    $s_html &= "</td>" & @CR
    $s_html &= "<td>&lt;textarea name='textareaExample' rows='5' cols='15'&gt;Hello!&lt;/textarea&gt;</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>" & @CR
    $s_html &= "<input type='checkbox' name='checkboxG1Example' value='gameBasketball'>Basketball<br>" & @CR
    $s_html &= "<input type='checkbox' name='checkboxG1Example' value='gameFootball'>Football<br>" & @CR
    $s_html &= "<input type='checkbox' name='checkboxG2Example' value='gameTennis' checked>Tennis<br>" & @CR
    $s_html &= "<input type='checkbox' name='checkboxG2Example' value='gameBaseball'>Baseball" & @CR
    $s_html &= "</td>" & @CR
    $s_html &= "<td>&lt;input type='checkbox' name='checkboxG1Example' value='gameBasketball'&gt;Basketball&lt;br&gt;<br>" & @CR
    $s_html &= "&lt;input type='checkbox' name='checkboxG1Example' value='gameFootball'&gt;Football&lt;br&gt;<br>" & @CR
    $s_html &= "&lt;input type='checkbox' name='checkboxG2Example' value='gameTennis' checked&gt;Tennis&lt;br&gt;<br>" & @CR
    $s_html &= "&lt;input type='checkbox' name='checkboxG2Example' value='gameBaseball'&gt;Baseball</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>" & @CR
    $s_html &= "<input type='radio' name='radioExample' value='vehicleAirplane'>Airplane<br>" & @CR
    $s_html &= "<input type='radio' name='radioExample' value='vehicleTrain' checked>Train<br>" & @CR
    $s_html &= "<input type='radio' name='radioExample' value='vehicleBoat'>Boat<br>" & @CR
    $s_html &= "<input type='radio' name='radioExample' value='vehicleCar'>Car</td>" & @CR
    $s_html &= "<td>&lt;input type='radio' name='radioExample' value='vehicleAirplane'&gt;Airplane&lt;br&gt;<br>" & @CR
    $s_html &= "&lt;input type='radio' name='radioExample' value='vehicleTrain' checked&gt;Train&lt;br&gt;<br>" & @CR
    $s_html &= "&lt;input type='radio' name='radioExample' value='vehicleBoat'&gt;Boat&lt;br&gt;<br>" & @CR
    $s_html &= "&lt;input type='radio' name='radioExample' value='vehicleCar'&gt;Car&lt;br&gt;</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>" & @CR
    $s_html &= "<select name='selectExample'>" & @CR
    $s_html &= "<option value='homepage.html'>Homepage" & @CR
    $s_html &= "<option value='midipage.html'>Midipage" & @CR
    $s_html &= "<option value='freepage.html'>Freepage" & @CR
    $s_html &= "</select>" & @CR
    $s_html &= "</td>" & @CR
    $s_html &= "<td>&lt;select name='selectExample'&gt;<br>" & @CR
    $s_html &= "&lt;option value='homepage.html'&gt;Homepage<br>" & @CR
    $s_html &= "&lt;option value='midipage.html'&gt;Midipage<br>" & @CR
    $s_html &= "&lt;option value='freepage.html'&gt;Freepage<br>" & @CR
    $s_html &= "&lt;/select&gt;</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>" & @CR
    $s_html &= "<select name='multipleSelectExample' size='6' multiple>" & @CR
    $s_html &= "<option value='Name1'>Aaron" & @CR
    $s_html &= "<option value='Name2'>Bruce" & @CR
    $s_html &= "<option value='Name3'>Carlos" & @CR
    $s_html &= "<option value='Name4'>Denis" & @CR
    $s_html &= "<option value='Name5'>Ed" & @CR
    $s_html &= "<option value='Name6'>Freddy" & @CR
    $s_html &= "</select>" & @CR
    $s_html &= "</td>" & @CR
    $s_html &= "<td>&lt;select name='multipleSelectExample' size='6' multiple&gt;<br>" & @CR
    $s_html &= "&lt;option value='Name1'&gt;Aaron<br>" & @CR
    $s_html &= "&lt;option value='Name2'&gt;Bruce<br>" & @CR
    $s_html &= "&lt;option value='Name3'&gt;Carlos<br>" & @CR
    $s_html &= "&lt;option value='Name4'&gt;Denis<br>" & @CR
    $s_html &= "&lt;option value='Name5'&gt;Ed<br>" & @CR
    $s_html &= "&lt;option value='Name6'&gt;Freddy<br>" & @CR
    $s_html &= "&lt;/select&gt;</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "<tr>" & @CR
    $s_html &= "<td>" & @CR
    $s_html &= "<input name='submitExample' type='submit' value='Submit'>" & @CR
    $s_html &= "<input name='resetExample' type='reset' value='Reset'>" & @CR
    $s_html &= "</td>" & @CR
    $s_html &= "<td>&lt;input name='submitExample' type='submit' value='Submit'&gt;<br>" & @CR
    $s_html &= "&lt;input name='resetExample' type='reset' value='Reset'&gt;</td>" & @CR
    $s_html &= "</tr>" & @CR
    $s_html &= "</table>" & @CR
    $s_html &= "<input type='hidden' name='hiddenExample' value='secret value'>" & @CR
    $s_html &= "</FORM>" & @CR
    $s_html &= "</BODY>" & @CR
    $s_html &= "</HTML>"
    
    Return $s_html
EndFunc

It's a mix of _IE_Example but instead of creating the object in it's own window the new object is embedded and it's content is the same. I hope it's correct. Incidentally, I've changed the ControlClick() function call to use ClassNameNN instead of the original format because of user locale.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hello

I encouter almost the same problem : it seems that a pop-up issued by javascript just hangs autoit.

Try first this script:

#include <IE.au3>
$Oie=_IECreate("http://sksbir.free.fr/test_html_popup_java.htm")
_IELoadWait($Oie)
$o_bouton=_IEGetObjByName($Oie,"bouton")
_IEAction($o_bouton, "Click")
MsgBox(0,"test","THE END")

the pop-up generated by autoit will appear only when you have closed the pop-up generated by IE. During this time, just try to close the script with the Autoit Icon in the systray : the systray icon have a realy weird behaviour...

Like Quacky, I solve this with a dual execution script , try this:

#include <IE.au3>

; script REENTRANT : le script fils lancé par le script père s'occupe de valider une fenetre pop-up
If $CmdLine[0]>0 Then
    If $CMDLINE[1]="checkpopup" Then
        $TEST=WinWait("Windows Internet Explorer","Press a button!",5)
        If $TEST<>0 Then
            $TEST=ControlClick("Windows Internet Explorer","Press a button","[CLASS:Button; INSTANCE:1]")
        EndIf
    EndIf
    WinWait("Windows Internet Explorer","You pressed OK!",5)
    sleep(1000)
    ControlClick("Windows Internet Explorer","You pressed OK!","[CLASS:Button; INSTANCE:1]")
    Exit 0
EndIf

$UNCFULLPATH="""" & @ScriptFullPath & """ "
If @Compiled Then
    $PREFIX = $UNCFULLPATH
Else
    $PREFIX = """" & @AutoItExe & """ /AutoIt3ExecuteScript " & $UNCFULLPATH
EndIf

$CMDE = $PREFIX & "checkpopup" ; cette commande permet de lancer la partie "fils" ci-dessus.




$Oie=_IECreate("http://sksbir.free.fr/test_html_popup_java.htm")
_IELoadWait($Oie)

$o_bouton=_IEGetObjByName($Oie,"bouton")
; on lance le fork FILS de ce script , chargé de refermer la fenetre qui va apparaitre quand on clique...
Run ( $CMDE )

_IEAction($o_bouton, "Click")
MsgBox(0,"test","THE END")

Any other ideas ?

ps : Of course, http://sksbir.free.fr/test_html_popup_java.htm is a sample to show the problem. I don't have access to the real pages I need to automate with autoit.

Edited by sksbir

Share this post


Link to post
Share on other sites

See the second example for _IEAction in the helpfile

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

See the second example for _IEAction in the helpfile

Dale

Thank's a lot :unsure:, this solution works great!

here is the new code for my example:

#include <IE.au3>


$oIE=_IECreate("http://sksbir.free.fr/test_html_popup_java.htm")
_IELoadWait($oIE)

$o_bouton=_IEGetObjByName($oIE,"bouton")

$hwnd = _IEPropertyGet($oIE, "hwnd")

_IEAction($o_bouton, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")


$TEST=WinWait("Windows Internet Explorer","Press a button!",5)
ControlClick("Windows Internet Explorer","Press a button","[CLASS:Button; INSTANCE:1]")

WinWait("Windows Internet Explorer","You pressed OK!",5)
sleep(1000)
ControlClick("Windows Internet Explorer","You pressed OK!","[CLASS:Button; INSTANCE:1]")

MsgBox(0,"test","END")

Sorry that you had to give your solution a second time 2 years after, but the first time, it was not so obvious to realize that you where right ( because of others replys without quoting)

Edited by sksbir

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