quacky Posted October 18, 2009 Posted October 18, 2009 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
Authenticity Posted October 18, 2009 Posted October 18, 2009 (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 October 18, 2009 by Authenticity
DaleHohm Posted October 18, 2009 Posted October 18, 2009 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
Authenticity Posted October 18, 2009 Posted October 18, 2009 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.
quacky Posted October 18, 2009 Author Posted October 18, 2009 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.
DaleHohm Posted October 18, 2009 Posted October 18, 2009 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
Authenticity Posted October 18, 2009 Posted October 18, 2009 expandcollapse popup#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><form name='ExampleForm' onsubmit='javascript:alert(""ExampleFormSubmitted"");' method='post'></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><input type='hidden' name='hiddenExample' value='secret value'></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><input type='text' name='textExample' value='http://' size='20' maxlength='30'></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><input type='password' name='passwordExample' size='10'></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><input type='file' name='fileExample'></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><input type='image' name='imageExample' alt='AutoIt Homepage' src='http://www.autoitscript.com/images/autoit_6_240x100.jpg'></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><textarea name='textareaExample' rows='5' cols='15'>Hello!</textarea></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><input type='checkbox' name='checkboxG1Example' value='gameBasketball'>Basketball<br><br>" & @CR $s_html &= "<input type='checkbox' name='checkboxG1Example' value='gameFootball'>Football<br><br>" & @CR $s_html &= "<input type='checkbox' name='checkboxG2Example' value='gameTennis' checked>Tennis<br><br>" & @CR $s_html &= "<input type='checkbox' name='checkboxG2Example' value='gameBaseball'>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><input type='radio' name='radioExample' value='vehicleAirplane'>Airplane<br><br>" & @CR $s_html &= "<input type='radio' name='radioExample' value='vehicleTrain' checked>Train<br><br>" & @CR $s_html &= "<input type='radio' name='radioExample' value='vehicleBoat'>Boat<br><br>" & @CR $s_html &= "<input type='radio' name='radioExample' value='vehicleCar'>Car<br></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><select name='selectExample'><br>" & @CR $s_html &= "<option value='homepage.html'>Homepage<br>" & @CR $s_html &= "<option value='midipage.html'>Midipage<br>" & @CR $s_html &= "<option value='freepage.html'>Freepage<br>" & @CR $s_html &= "</select></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><select name='multipleSelectExample' size='6' multiple><br>" & @CR $s_html &= "<option value='Name1'>Aaron<br>" & @CR $s_html &= "<option value='Name2'>Bruce<br>" & @CR $s_html &= "<option value='Name3'>Carlos<br>" & @CR $s_html &= "<option value='Name4'>Denis<br>" & @CR $s_html &= "<option value='Name5'>Ed<br>" & @CR $s_html &= "<option value='Name6'>Freddy<br>" & @CR $s_html &= "</select></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><input name='submitExample' type='submit' value='Submit'><br>" & @CR $s_html &= "<input name='resetExample' type='reset' value='Reset'></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.
sksbir Posted May 11, 2011 Posted May 11, 2011 (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: expandcollapse popup#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 May 11, 2011 by sksbir
DaleHohm Posted May 12, 2011 Posted May 12, 2011 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
sksbir Posted May 12, 2011 Posted May 12, 2011 (edited) See the second example for _IEAction in the helpfile Dale Thank's a lot , 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 May 12, 2011 by sksbir
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