Sign in to follow this  
Followers 0
JonathanChan

Automating Internet Explorer

4 posts in this topic

#1 ·  Posted (edited)

Hello...

I'm interested in automating an IE window to submit data to a form (log in for me automatically), but I want to do it from IE, not by Send()... I found a way to do it in VB Script; can Autoit somehow send VBScript commands?

the code in VBscript is

Dim WshShell, oIE
Set WshShell = WScript.CreateObject("WScript.Shell")

    Set oIE = CreateObject("InternetExplorer.Application")
    oIE.navigate "about:blank" 
    oIE.document.body.innerHTML= _
    "<Form name=frm1 id=frm1 action=" & args.Item(0) & " METHOD=POST><input type=text name=UserID value=" & $username & "><input type=text name=password value=" & $password & "><input type=submit></form>"
    oIE.document.frm1.submit()
    wscript.sleep 1000
    oIE.Visible = True
    WScript.Quit 1

btw, i don't want to run the vbscript because i want to compile this autoit script and distribute it as 1 file...

JonathaN ChaN

Edited by JonathanChan

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This can readily be done with straight AutoIt code with the COM interface in the latest beta, but you may want to check out the IE Automation UDF Library. I takes care of things like waiting for the page load to complete before moving to the next command.

Your code would be something like this:

#include <IE.au3>

$username = "your-username"
$password = "your password"
$oIE = _IECreate()
_IEBodyWriteHTML($oIE, "<Form name=frm1 id=frm1 action=" & $CmdLine[1] & " METHOD=POST><input type=text name=UserID value=" & $username & "><input type=text name=password value=" & $password & "><input type=submit></form>")
_IEFormSubmit(_IEFormGetObjByName($oIE, "frm1"))
_IEQuit($oIE)

Exit

Dale

Edit: added lines for Username and Password not in vbs example, added missing object reference in _IEBodyWriteHTML

Edited by DaleHohm

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

This can readily be done with straight AutoIt code with the COM interface in the latest beta, but you may want to check out the IE Automation UDF Library.  I takes care of things like waiting for the page load to complete before moving to the next command.

Your code would be something like this:

#include <IE.au3>

$username = "your-username"
$password = "your password"
$oIE = _IECreate()
_IEBodyWriteHTML($oIE, "<Form name=frm1 id=frm1 action=" & $CmdLine[1] & " METHOD=POST><input type=text name=UserID value=" & $username & "><input type=text name=password value=" & $password & "><input type=submit></form>")
_IEFormSubmit(_IEFormGetObjByName($oIE, "frm1"))
_IEQuit($oIE)

Exit

Dale

Edit: added lines for Username and Password not in vbs example, added missing object reference in _IEBodyWriteHTML

<{POST_SNAPBACK}>

Looks promising... How "beta" is the latest AutoIt with COM support? Maybe i'll wait till it's in the regular tree... boy! Autoit becomes as powerful as any language more and more each day.... and in my opinion, much less confusing and more concise than VB or any other scripting languages i've looked at...

Share this post


Link to post
Share on other sites

In my opinion, the beta is very solid. The beta is pretty mature now -- there is a lot of active testing of it here and the devs are fantastic about quickly fixing issues once they have been uncovered.

Your milage may vary, but the new features are well worth the investment for me and I have had very little trouble with the beta.

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

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