Jump to content
Sign in to follow this  
DaleHohm

Internet Explorer Automation UDF library

Recommended Posts

#include <IE.au3>


$oIE =_IECreate( )
_IENavigate($oIE, "**********")
_IELoadWait($oIE,2000)
WinSetState ( "*************", "", @SW_MAXIMIZE  ) 



Func Mouse1()
MouseMove(46,84)

EndFunc

DIM $rand_[13]

FOR $X = 1 TO 12

$rand_A = Chr(Random(Asc("A"), Asc("Z"), 1))

$rand_B = Random(0, 9, 1)

If Random() < 0.5 Then
$rand_[$X] = $rand_A
Else
$rand_[$X] = $rand_B
Endif
$crap = String("BK" & $rand_[1] & $rand_[2] & "-" & $rand_[3] & $rand_[4] & $rand_[5] & $rand_[6] & $rand_[7] & $rand_[8] & "-" & "X" & $rand_[9] & $rand_[10] & $rand_[11] & $rand_[12] & "2" )
Next



DIM $BAND_[99999]
FOR $B = 1 TO 99999
$o_form = _IEFormGetObjByName($oIE, "********")
_IELoadWait($oIE,2000) 
_IEFormElementSetValue($oIE.document.GetElementById("CCBox"),$crap)
_IELoadWait($oIE,2000) 
$o_SubmitButton = $oIE.document.getElementById("SubmitBtn")
_IELoadWait($oIE,2000) 
$o_SubmitButton.click
_IELoadWait($oIE,2000) 
MouseMove(46,84)
 MouseDown("left")
MouseUp("left")
_IEFormElementSetValue($oIE.document.GetElementById("CCBox"),$crap)
_IELoadWait($oIE,2000) 
NEXT

Ok I put the code into a loop... The loops works except when its supposed to place the new random code into the "CCBox" agian.. IT WILL NOT WHICH IS PISSING ME OFF. Ive been working on this for 3 days ( around 3 hours)

Ive had to try many implementations.

Maybe I have to clear the old code.. that's there since I press the Goback button with the mouse..

Share this post


Link to post
Share on other sites

OK, so I structured and simplified your code and I think it should be obvious where your trouble is now. You have two For...Next loops. In the first you set $crap to 12 random values (for no apparent reason) and in the second, you set the value of the text box to the 12th random value of $crap 99999 (times two) times.

I hardly think that is what you intend to do. So, unless I made mistakes in revamping you code, you are having simple code logic problems and the harder stuff with IE and DOM is working as expected.

Dale

#include <IE.au3>

Dim $rand_[13]
Dim $BAND_[99999]

$oIE =_IECreate( )
_IENavigate($oIE, "**********")
WinSetState ( "*************", "", @SW_MAXIMIZE  ) 

For $X = 1 TO 12
    $rand_A = Chr(Random(Asc("A"), Asc("Z"), 1))
    $rand_B = Random(0, 9, 1)
    If Random() < 0.5 Then  
        $rand_[$X] = $rand_A
    Else
        $rand_[$X] = $rand_B
    Endif
    $crap = String("BK" & $rand_[1] & $rand_[2] & "-" & $rand_[3] & $rand_[4] & $rand_[5] & $rand_[6] & $rand_[7] & $rand_[8] & "-" & "X" & $rand_[9] & $rand_[10] & $rand_[11] & $rand_[12] & "2" )
Next

For $B = 1 TO 99999
    _IEFormElementSetValue($oIE.document.GetElementById("CCBox"),$crap)
    $oIE.document.getElementById("SubmitBtn").click
    _IELoadWait($oIE)
    Mouse1()
    _IEFormElementSetValue($oIE.document.GetElementById("CCBox"),$crap)
Next

Exit

Func Mouse1()
    MouseMove(46,84)
    MouseDown("left")
    MouseUp("left")
EndFunc

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

Hmm, I'm having trouble in dealing with forms that don't have names. Using Dale's collection table function, it gives me a result of a number for the forms that are nameless. Would someone know a work-around method that can deal with this type of situation?

- Lord Felix


Share this post


Link to post
Share on other sites

You can also reference forms (or any element) by index as well as by name.

; Function Name: _IEFormGetObjByIndex()

; Description: Obtain an object variable reference to a form by 0-based index

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

:whistle: Can't believe I missed that.

Hmm, well I'm having trouble with a submit button. I've tried the _IEFormSubmit and also the clicking method that you've mentioned, but neither seem to be working. I've managed to grab the source of the form below.

<form action="posting.php" method="post" name="post" onsubmit="return checkForm(this)">

<textarea name="message" style="width:500px;" rows="15" cols="40" wrap="virtual" tabindex="3" class="post" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);"></textarea>
<input type="hidden" name="preview" value="" />
<input type="hidden" name="post" value="" />
<input type="hidden" name="add_poll_option" value="" />
<input type="hidden" name="delete_poll" value="" />
<input type="hidden" name="update_poll_option" value="" />
<input type="hidden" name="delete_poll_option" value="" />
<input type="hidden" name="delete_poll_option_number" value="0" />
<input type="hidden" name="mode" value="reply" />
<input type="hidden" name="t" value="7915989" />
<input type="hidden" name="f" value="28" />
<input type="hidden" name="p" value="" />
<input type="hidden" name="nonce" value="1014650421" />
<input type="hidden" name="created" value="1123520267" />
<input type="hidden" name="digest" value="665265709" />
<input type="image" src="http://******/images/template/button/submit_preview.gif" onclick="document.post.preview.value='true';" alt="Preview" title="Preivew" width="67" height="15"/>
<input type="image" src="http://******/images/template/button/submit_submit.gif" onclick="document.post.post.value='true';" alt="Submit" title="Submit" width="67" height="15" />

</form>

I've tried many attempts, but I can't seem to figure out how to get the form to submit itself. :dance: Help would be appriciated.


Share this post


Link to post
Share on other sites

Hi everyone

I'm very new to AutoIt, I've only used AutoIt to do a few simple tasks in unattended Windows installation. When I found Internet Explorer Automation UDF Library, I think it's great to use it to do some internet related tasks. But when I inclued IE3.au3 in my scripts, I always get error messages similar to the screenshot posted below

Posted Image

I've AutoIt v3.1.1.62 beta installed on my computer, could anyone kindly help me. That would be appreciated.

Thx

Share this post


Link to post
Share on other sites

I've AutoIt v3.1.1.62 beta installed on my computer, could anyone kindly help me. That would be appreciated.

<{POST_SNAPBACK}>

There is some text at the top of the base note where you downloaded the file in bold that says Important. Please read that.

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

:whistle: Can't believe I missed that.

Hmm, well I'm having trouble with a submit button. I've tried the _IEFormSubmit and also the clicking method that you've mentioned, but neither seem to be working. I've managed to grab the source of the form below.

<form action="posting.php" method="post" name="post" onsubmit="return checkForm(this)">

<textarea name="message" style="width:500px;" rows="15" cols="40" wrap="virtual" tabindex="3" class="post" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);"></textarea>
<input type="hidden" name="preview" value="" />
<input type="hidden" name="post" value="" />
<input type="hidden" name="add_poll_option" value="" />
<input type="hidden" name="delete_poll" value="" />
<input type="hidden" name="update_poll_option" value="" />
<input type="hidden" name="delete_poll_option" value="" />
<input type="hidden" name="delete_poll_option_number" value="0" />
<input type="hidden" name="mode" value="reply" />
<input type="hidden" name="t" value="7915989" />
<input type="hidden" name="f" value="28" />
<input type="hidden" name="p" value="" />
<input type="hidden" name="nonce" value="1014650421" />
<input type="hidden" name="created" value="1123520267" />
<input type="hidden" name="digest" value="665265709" />
<input type="image" src="http://******/images/template/button/submit_preview.gif" onclick="document.post.preview.value='true';" alt="Preview" title="Preivew" width="67" height="15"/>
<input type="image" src="http://******/images/template/button/submit_submit.gif" onclick="document.post.post.value='true';" alt="Submit" title="Submit" width="67" height="15" />

</form>

I've tried many attempts, but I can't seem to figure out how to get the form to submit itself.  :dance: Help would be appriciated.

<{POST_SNAPBACK}>

Looks like you need to perform a .click action on that <input type="image" Submit button. Unfortunately for you they did not give it a Name or an ID -- you'll need to address it by Index. Please see reply 37 in this note for a script to help you figure this out.

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

Looks like you need to perform a .click action on that <input type="image" Submit button.  Unfortunately for you they did not give it a Name or an ID -- you'll need to address it by Index.  Please see reply 37 in this note for a script to help you figure this out.

Dale

<{POST_SNAPBACK}>

Actually, I have already used the script, but oddly enough the last two did not show up in the result. I've went ahead and added two to the last index returned by the script and codded the program to .click on the object element that I had referenced. When I ran the program though, it came up with a object reference error.

Share this post


Link to post
Share on other sites

Actually, I have already used the script, but oddly enough the last two did not show up in the result. I've went ahead and added two to the last index returned by the script and codded the program to .click on the object element that I had referenced. When I ran the program though, it came up with a object reference error.

<{POST_SNAPBACK}>

It may be that the type=image isn't showing up as a form element. Try looking at the list of ALL elements and try to find it and reference it by index in the _IETagNameAllGetCollection ($oIE) collection.

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

It may be that the type=image isn't showing up as a form element.  Try looking at the list of ALL elements and try to find it and reference it by index in the _IETagNameAllGetCollection ($oIE) collection.

Dale

<{POST_SNAPBACK}>

Alright, I've located the index within the collection. Sorry for all of the questions, but which method would I use to define the object using the new index? Edited by Lord Felix

Share this post


Link to post
Share on other sites

Alright, I've located the index within the collection. Sorry for all of the questions, but which method would I use to define the object using the new index?

<{POST_SNAPBACK}>

$o_all = _IETagNameAllGetCollection ($oIE)
$o_button = $o_all.item(index)
$o_button.click

or just

$o_all = _IETagNameAllGetCollection ($oIE)
$o_all.item(index).click

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

There is some text at the top of the base note where you downloaded the file in bold that says Important.  Please read that.

Dale

<{POST_SNAPBACK}>

Sorry about that. I've downloaded AutoIt v3.1.1.66 beta and the problem solved. Thanks.

Share this post


Link to post
Share on other sites

$o_all = _IETagNameAllGetCollection ($oIE)
$o_button = $o_all.item(index)
$o_button.click

or just

$o_all = _IETagNameAllGetCollection ($oIE)
$o_all.item(index).click

Dale

<{POST_SNAPBACK}>

Thanks Dale :whistle: Edited by Lord Felix

Share this post


Link to post
Share on other sites

Hi All,

I'm a newbie. I'm trying to run some of the examples, but receive the following error. What am I missing? It must something simple...

>"C:\Program Files\AutoIt3\SciTe\CompileAU3\CompileAU3.exe" /run /beta /ErrorStdOut /in "C:\AutoIT3Scripts\Test.au3" /autoit3dir "C:\Program Files\AutoIt3\beta" /UserParams

>Running AU3Check...C:\Program Files\AutoIt3\SciTe\Defs\Unstable\Au3Check\au3check.dat

C:\Program Files\AutoIt3\Include\IE.au3(278,84) : ERROR: syntax error

If StringInStr($o_window.document.title, $s_string) &gt; 0 Then

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\Include\IE.au3(278,84) : ERROR: multi-line 'If' missing 'Then'.

If StringInStr($o_window.document.title, $s_string) &gt; 0 Then

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Share this post


Link to post
Share on other sites

                    If StringInStr($o_window.document.title, $s_string) &gt; 0 Then

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\Include\IE.au3(278,84) : ERROR: multi-line 'If' missing 'Then'.

                    If StringInStr($o_window.document.title, $s_string) &gt; 0 Then

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

<{POST_SNAPBACK}>

Looks like your file download of IE.au3 didn't go well ($gt; should be >). Please try downloading it again.

Edit: Hint -- right-click the file and do a Save As

Dale

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

Looks like your file download of IE.au3 didn't go well ($gt; should be >).  Please try downloading it again.

Edit: Hint -- right-click the file and do a Save As

Dale

<{POST_SNAPBACK}>

Dale,

You were right the download was corrupted. Works great now!

Thanks!

Jim

Share this post


Link to post
Share on other sites

I am getting an error when using IE.au3, error is:

IE.au3 (848) : ==> Variable must be of type "Object".:

If IsObj($o_object.elements.item ($s_name, $i_index)) Then

If IsObj($o_object^ ERROR

Script looks like:

#include <IE.au3>

HotKeySet("^+l", "neatadminLogin")
HotKeySet("^+f", "getFormInfo")
HotKeySet("^+t", "terminate")

$address = ""
$user32 = DllOpen("user32")

While 1 
    sleep(10)
WEnd

func neatadminLogin()
    
;prompt for dev, test or uat address
    SplashTextOn("Choose the Environment","Press D for Development" & @CRLF & "Press T for System Test" & @CRLF & "Press U for UAT","200","60","-1","-1",0,"Tahoma","10","400")
            
    while 1
        If _IsPressed(44) = 1 Then 
            $address = "http://n-dev-as1:7777/neat"
            ExitLoop
        endIf
        If _IsPressed(54) = 1 Then 
            $address = "http://n-test-as1:7777/neat"
            ExitLoop
        endIf
        If _IsPressed(55) = 1 Then 
            $address = "http://n-test-as1:7779/neat"
            ExitLoop
        endIf
        sleep(1)
    wend
    
    SplashOff()     
        
; Create a browser window and navigate to the web address
    $oIE = _IECreate()
    _IENavigate($oIE, $address)
    
;Maximize the window
    WinSetState("NEAT - Microsoft Internet Explorer", "", @SW_MAXIMIZE)
    
;acquire the deviously hidden dynamic password field name.
    $oDoc = _IEDocumentGetObj($oIE) 
    $forms = _IEFormGetCollection($oDoc)
    For $form in $forms
        $fes = _IEFormElementGetCollection($form)
        For $fe in $fes
            if StringInStr($fe.name, "password") then
                local $passwordField = $fe.name
            endIf
        Next
    Next    
    
; get pointers to the login form and username and password fields
    $o_form = _IEFormGetObjByName($oIE, "my_account_fm")
    $o_login = _IEFormElementGetObjByName($o_form, "my_account_login")
    $o_password = _IEFormElementGetObjByName($o_form, $passwordField)
    
; Set field values and submit the form
    _IEFormElementSetValue($o_login, "*******")
    _IEFormElementSetValue($o_password, "*******")
    _IEFormSubmit($o_form)
endFunc

;

Func _IsPressed($hexKey)
    Local $aR, $bRv
    $hexKey = '0x' & $hexKey
    $aR = DllCall($user32, "int", "GetAsyncKeyState", "int", $hexKey)   
    If $aR[0] <> 0 Then
        $bRv = 1
    Else
        $bRv = 0
    EndIf   
    Return $bRv
EndFunc  

;

func getFormInfo()
    $oIE = _IECreate()
    _IENavigate($oIE, "http://n-dev-as1:7777/neat/")
    $oDoc = _IEDocumentGetObj($oIE)
    
    $forms = _IEFormGetCollection($oDoc)
    For $form in $forms
        ConsoleWrite("Form name: " & $form.name & @CR)
        $fes = _IEFormElementGetCollection($form)
        For $fe in $fes
            ConsoleWrite(@Tab & $fe.name & @TAB & "Type: " & $fe.type & @CR)
        Next
    Next
endFunc

;

Func Terminate()
    DllClose($user32)
    Exit
EndFunc

;

Share this post


Link to post
Share on other sites

Edit:

What I originally posted here was all bogus advice -- I should have read my own code before replying.

I'm removing the just so as not to throw anyone off track.

See the next post for the user's diagnosis of the problem.

Dale

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
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...