Sign in to follow this  
Followers 0
horstj

Help with IE form fill

11 posts in this topic

Hi All,

I am having a bit of trouble filling in some input boxes on a certain website. I have tried all kinds of different iterations of the following script, but can't get anything to work.

#include <IE.au3>
Run("C:\Program Files (x86)\Internet Explorer\iexplore.exe -new http://acc.rollernet.us/","")
$RollerHwnd = WinWaitActive("[TITLE:Roller Network Control Center - Windows Internet Explorer; CLASS:IEFrame]")
$rollerIE = _IEAttach($RollerHwnd,"HWND")
$rollerForm = _IEFormGetCollection($rollerIE)
;Logs into the Rollernet admin portal
$roller_username = _IEFormElementGetObjByName($rollerForm,"username")
$roller_password = _IEFormElementGetObjByName($rollerForm,"password")
_IEFormElementSetValue($roller_username,"Username")
_IEFormElementSetValue($roller_password,"Password")

I have used a variation of this exact code for another website without any problems. Does anyone see what I am missing? Any help would be greatly appreciated!

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

You need to add some error checking to your code! Every _IE* function sets @error if there was a problem.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks water. I didn't do any error checking with @error, but here is the output when I run the script:

IE.au3 V2.4-0 Error from function _IEPropertyGet, $_IEStatus_InvalidObjectType

--> IE.au3 V2.4-0 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidObjectType

--> IE.au3 V2.4-0 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidObjectType

--> IE.au3 V2.4-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType

--> IE.au3 V2.4-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType

From all of my testing, it seems that the problem exists around the _IEFormGetCollection function. Is that the best way to get the password and username input fields? They are in an unamed form which makes things interesting as well.

Share this post


Link to post
Share on other sites

Thanks DedekPredek. Did you test that out on your machine at all? I had tried that before and it actually gives me the same errors as my previous post, but with

--> IE.au3 V2.4-0 Warning from function _IEFormGetCollection, $_IEStatus_NoMatch

added. Any other suggestions?

Share this post


Link to post
Share on other sites

horstj,

Try it with WinWait and _IELoadWait, it works for me

#include <IE.au3>
Run("C:\Program Files (x86)\Internet Explorer\iexplore.exe -new https://acc.rollernet.us/","")
$RollerHwnd = WinWait("Roller Network Control Center - Windows Internet Explorer","")
$rollerIE = _IEAttach($RollerHwnd,"HWND")
_IELoadWait($rollerIE)

DedekPredek

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Dedek, Sorry for my ignorance here, but would my code now look like this

#include <IE.au3>
Run("C:\Program Files (x86)\Internet Explorer\iexplore.exe -new https://acc.rollernet.us/","")
$RollerHwnd = WinWait("Roller Network Control Center - Windows Internet Explorer","")
$rollerIE = _IEAttach($RollerHwnd,"HWND")
_IELoadWait($rollerIE)
$rollerForm = _IEFormGetCollection($rollerIE)
;Logs into the Rollernet admin portal
$roller_username = _IEFormElementGetObjByName($rollerForm,"username")
$roller_password = _IEFormElementGetObjByName($rollerForm,"password")
_IEFormElementSetValue($roller_username,"Username")
_IEFormElementSetValue($roller_password,"Password")

I still cannot get it to fill in the username and password fields.

Edited by horstj

Share this post


Link to post
Share on other sites

As I said in post #2 you need to add some error checking. Which of the functions you call sets @error?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#include <IE.au3>
$oIE=_IECreate("https://acc.rollernet.us")
$oObj = _IEGetObjByName($oIE,"username")
_IEPropertySet($oObj,"innertext","MyUserId")
$oObj = _IEGetObjByName($oIE,"password")
_IEPropertySet($oObj,"innertext","MyPassword")
$oObj = _IEGetObjByName($oIE,"submit")
_IEAction($oObj,"click")
Exit


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Wow... that was way easier than I was making it! Thanks Exit, that worked perfectly.

Share this post


Link to post
Share on other sites

As you can see from the help file:

_IEAttach: 7 ($_IEStatus_NoMatch) = No Match ==> The IE instance you try to attach to couldn't be found

_IELoadWait: 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ==> Error caused by unsuccessfull _IEAttach


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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

  • Similar Content

    • Robdog1955
      By Robdog1955
      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  
    • Dent
      By Dent
      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.


    • milos83
      By milos83
      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?
       
      Create IE:
      #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)  
       
      attach.au3
      create.au3
    • Tippex
      By Tippex
      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?
    • nassausky
      By nassausky
      Hi all,
       
      Anyone have any idea how to close all open tabs except a specific one I manually open.  Assuming I don't know what is open in all the tabs except just the one I want to keep open.
       
      I didn't want to use sendkeys and I was trying to use the following code to list the title (or url) of the 3 open tabs and  after I got that part working I would just close the other 2. This sample only displays the title of the first open tab
      #include <IE.au3> Const $ie_new_in_tab = 0x0800 $oIE = _IECreate("https://www.autoitscript.com") __IENavigate($oIE, "https://www.autoitscript.com/forum/", 1, $ie_new_in_tab) ;(obj,url,wait,param) __IENavigate($oIE, "https://www.google.com/", 1, $ie_new_in_tab) ;(obj,url,wait,param) Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIE While 1     $oIE = _IEAttach("", "instance", $i)     If @error = $_IEStatus_NoMatch Then ExitLoop     ConsoleWrite(_IEPropertyGet($oIE, "title") & @CRLF)     ReDim $aIE[$i + 1]     $aIE[$i] = $oIE ;each item holds object     $aIE[0] = $i ;first item holds count     $i += 1 WEnd MsgBox($MB_SYSTEMMODAL, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) ; This doesn't return the list of tabs in the console just the first tab  
      Thanks for any and all help