6 posts in this topic
I'm trying to click a button on a web page. I have added a couple of MsgBox lines to allow me to watch what happens on the page. As you can see the first half of my script enters data into text boxes on the page. I have no problem there. I just cannot click on the region buttons. The "set focus" line causes an outline to appear around the EU button and the "click button" line causes the "Pick a Region" text to disappear. Here is the code I have so far.
#include <IE.au3> Local $oIE = _IECreate("http://questchecker.com/") Local $iQuestID = "123456" Local $sCharacterName = "CharacterName" Local $colForms = _IEFormGetCollection($oIE) $iCount = 0 For $oForm In $colForms $oFormElements = _IEFormElementGetCollection($oForm) For $oFormElement In $oFormElements $iCount = $iCount + 1 Local $sTagName = StringLower($oFormElement.tagName) Local $sElementType = $oFormElement.type Local $sElementName = $oFormElement.name Switch $iCount Case 6 _IEFormElementSetValue($oFormElement, "MyRealm", 0) ; realm Case 7 _IEFormElementSetValue($oFormElement, $sCharacterName, 0) Case 8 _IEFormElementSetValue($oFormElement, $iQuestID, 0) EndSwitch Next Next Local $oButtons = _IEGetObjByName($oIE, "questForm") For $oButton In $oButtons If _IEFormElementGetValue($oButton) = "US" Then MsgBox(0, "", "Click Okay to set focus") _IEAction($oButton, "focus") MsgBox(0, "", "Click Okay to click button") _IEAction($oButton, "click") ExitLoop EndIf Next MsgBox(0, "", "Click Okay to quit") _IEQuit($oIE) Exit
As the title says. I open IE11 and navigate to a page with the following HTML5 file upload container in Capture0.JPG
I want to click Add Files but I haven't been able to. Here's the code that handles the Add Files button in Capture.JPG
_IEGetObjectById and then using _IEAction to click it doesn't work. I can't give access to the actual page unfortunately because it's password protected.
All suggestions welcome.
I have one script that creates _IECreateEmbedded and another script that does _IEAttach.
I do this because when autoit is doing something, the Embedded IE starts stalling (eg jquery progress animation)
But there is a new problem.
When IE is having its own process (like in the example above) any _IE command is slow (in the script that Attaches).
Here is a comparison of when its in separate and when its in same process:
Separate process _IETagNameGetCollection : 5000ms
Separate process _IEAction: 850ms
Same process _IETagNameGetCollection : 1ms
Same proccess _IEAction: 135ms
If I try to attach to an embedded IE that is done in c#, I get lightning fast results.
As you can see, _IE functions work very slow when the embedded IE we are attaching to is made in Autoit.
I did a test and if I empty the WHILE loop in IE process I get these results(but the cpu is at 30% as expected):
Separate process _IETagNameGetCollection : 33ms
Separate process _IEAction: 13ms
It slows down if you put anything (like GUIGetMsg) in the WHILE loop.
How do I fix this?
#include <GUIConstantsEx.au3> #include <IE.au3> #include <WindowsConstants.au3> Local $oIE = _IECreateEmbedded() GUICreate("My Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) GUICtrlCreateObj($oIE, 10, 40, 600, 360) GUISetState(@SW_SHOW) ;Show GUI _IENavigate($oIE, "http://www.autoitscript.com") $timer = TimerInit() $oLink = _IETagNameGetCollection($oIE, "a", 3) ;takes 1ms ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() _IEAction($oLink, "click") ;takes 135ms ConsoleWrite(TimerDiff($timer) & @CRLF) While 1 Local $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd
Attach to IE:
#include <IE.au3> Local $oIE = _IEAttach("My Embedded Web control Test", "embedded") $timer = TimerInit() $oLink = _IETagNameGetCollection($oIE, "a", 3) ; 5000ms ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() _IEAction($oLink, "click") ; 850ms ConsoleWrite(TimerDiff($timer) & @CRLF)
An example on how to inject jQuery into a web page
It can be useful to manage the page from AutoIt using jQuery.
Idea from here: http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
Suggestions and improvements are welcome
I have a problem trying to use _IEAttach to recover control after a Windows Explorer reset (e.g. on Windows 7), since all the
InternetExplorer.Application objects appear to be destroyed by this event. An example of this is when a PC has some kind of fault causing a pop-up error message "Windows Explorer has stopped working". I can simulate this event by using Windows Task Manager to end the Explorer.exe process then to file, new task (run...) Explorer.exe
After this event, _IEAttach gives an @error of:
7 ($_IEStatus_NoMatch) - No Match
However, using WinList() followed by WinGetText() I can recover the URL for an IE session that has lost its
InternetExplorer.Application object which could be used to _IECreate a new session (the $iTryAttach fails) and WinKill() the original session but the result is a if a refresh had been done (any form entries are lost) . Unfortunately form entries do not appear as text or hidden text to Windows so I'm looking for the best way to read the contents of an Internet Explorer screen (even if just text without structure).
When there is no InternetExplorer.Application object (because of some Windows fault) but still with an Internet Explorer session running, I tried to read its contents by a "Select All" & "Copy to Clipboard" but its form entries are blanked and combo boxes choices are all displayed with no way of finding out which ones were selected.
Local $ClipBoardSave = _ClipBoard_GetData() ;not ClipGet() which is text only ClipPut("") ;Clear User's Clipboard Local $sText = "" Local $hWnd = WinActivate("Window Title", "") If IsHWnd($hWnd) Then Local $bStatusCtrlSend = ControlSend("Window Title", "", "", "^a^c") If $bStatusCtrlSend Then Local $bStatusCtrlClick = ControlClick("Window Title", "", "") If $bStatusCtrlClick Then $sText = ClipGet() _ClipBoard_SetData($ClipBoardSave) ;not ClipPut($ClipBoardSave) which is text only
Is there a solution to this please?