Sign in to follow this  
Followers 0
jacob_1998_1999

_IECreate vs _IEAttach

15 posts in this topic

#1 ·  Posted (edited)

I'm going to put the code to the IECreate first, that works.. Then I'll post the IEAttach code that throws an error from IE.au3.

#include <IE.au3>
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")


$id = 1197
$oIE = 0


_EgweneLogIn()
_Fullbleed()
_Fullbleed()

while 1
sleep(100)
Wend


Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is Paused',0,0)
    WEnd
    ToolTip("")
EndFunc

Func _EgweneLogIn()
    $oIE = _IEcreate("http://www.xxxxxxxxx/login.php",0,1,0,1)
    _IEloadwait($oIE)
    WinSetState("xxxxxxxx.net", "", @SW_MAXIMIZE)
    $oForm = _IEFormGetObjByname($oIE,0)
    $username = _IEFormElementGetObjByname($oForm,"email")
    _IEFormElementSetValue($username,"xxxxxxxxxxxxxxxxx")
    $password = _IEFormElementGetObjByname($oForm,"password")
    _IEFormElementSetValue($password,"xxxxxxxxxxxxxxxxx")
    $oButton = _IEFormElementGetObjByName($oForm, "submit")
    $oButton.click()
    _IELoadWait($oIE)
EndFunc

Func _Fullbleed()
    $num = 0
    while 1
        If $num = 4 Then ExitLoop
        $oForm1 = _IEFormGetObjByName($oIE,0,1)
        $oSelect = _IEFormElementGetObjByName ($oForm1, "id")
        For $i = 1 To 1
        _IEFormElementOptionselect ($oSelect, $num, 1, "byIndex")
        Next
        $obutton1 = _IEFormElementGetObjByName($oForm1, "submit")
        $obutton1.click()
        _IELoadWait($oIE)
        _IENavigate($oIE,"www.xxxxxxxxxxx.net/d.php?id=" & $id)
        _IELoadWait($oIE)
        $oForm = _IEFormGetObjByname($oIE,"transact")
        $obutton = _IEFormElementGetObjByName($oForm, "submit")
        $obutton.click()
        _IELoadWait($oIE)
        _IENavigate($oIE,"www.xxxxxxxxxx.net/d.php?id=" & $id)
        _IELoadWait($oIE)
        $num = $num + 1
    WEnd
EndFunc

;;; Now the code that doesn't work.

#include <IE.au3>
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")


$id = 1197
$oIE = 0


_EgweneLogIn()
_Fullbleed()
_Fullbleed()

while 1
sleep(100)
Wend


Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is Paused',0,0)
    WEnd
    ToolTip("")
EndFunc

Func _EgweneLogIn()
    Opt("WinTitleMatchMode",4)
    Run("C:\Egwene.exe")
    WinWait("Egwene","")
        If Not WinActive("Egwene","") Then WinActivate("Egwene","")
        WinWaitActive("Egwene","")
    $oIE = _IEAttach( "Egwene", "Embedded")
    $oForm = _IEFormGetObjByname($oIE,0)
    $username = _IEFormElementGetObjByname($oForm,"email")
    _IEFormElementSetValue($username,"xxxxxxxxxxxxxxxxx")
    $password = _IEFormElementGetObjByname($oForm,"password")
    _IEFormElementSetValue($password,"xxxxxxxxxxxxxxxxx")
    $oButton = _IEFormElementGetObjByName($oForm, "submit")
    $oButton.click()
EndFunc

Func _Fullbleed()
    $num = 0
    while 1
        If $num = 4 Then ExitLoop
        $oForm1 = _IEFormGetObjByName($oIE,0,1)
        $oSelect = _IEFormElementGetObjByName ($oForm1, "id")
        For $i = 1 To 1
        _IEFormElementOptionselect ($oSelect, $num, 1, "byIndex")
        Next
        $obutton1 = _IEFormElementGetObjByName($oForm1, "submit")
        $obutton1.click()
        _IELoadWait($oIE)
        _IENavigate($oIE,"www.xxxxxxxxxxx.net/d.php?id=" & $id)
        _IELoadWait($oIE)
        $oForm = _IEFormGetObjByname($oIE,"transact")
        $obutton = _IEFormElementGetObjByName($oForm, "submit")
        $obutton.click()
        _IELoadWait($oIE)
        _IENavigate($oIE,"www.xxxxxxxxxx.net/d.php?id=" & $id)
        _IELoadWait($oIE)
        $num = $num + 1
    WEnd
EndFunc

The error it throws is as follows:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\testtest.au3" /autoit3dir "C:\Program Files\AutoIt3\beta" /UserParams

+>12:14:55 Starting AutoIt3Wrapper v.1.9.2

>Running AU3Check (1.54.9.0) from:C:\Program Files\AutoIt3\beta

+>12:14:55 AU3Check ended.rc:0

>Running:(3.2.5.4):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\testtest.au3"

--> IE.au3 V2.3-1 Warning from function _IEFormElementGetObjByName, $_IEStatus_NoMatch

--> IE.au3 V2.3-1 Error from function _IEFormElementOptionselect, $_IEStatus_InvalidDataType

--> IE.au3 V2.3-1 Warning from function _IELoadWait, $_IEStatus_AccessIsDenied (Cannot verify readyState. Likely casue: cross-site scripting security restriction.)

--> IE.au3 V2.3-1 Warning from function _IELoadWait, $_IEStatus_AccessIsDenied (Cannot verify readyState. Likely casue: cross-site scripting security restriction.)

C:\Program Files\AutoIt3\beta\Include\IE.au3 (1154) : ==> The requested action with this object has failed.:

$o_col = $o_object.document.forms.item ($s_Name)

$o_col = $o_object.document^ ERROR

->12:15:39 AutoIT3.exe ended.rc:1

+>12:15:39 AutoIt3Wrapper Finished

>Exit code: 1 Time: 44.732

Any clues? Thank you in advance for any and all help.

Jacob

Edited by jacob_1998_1999

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

In the instance where you are using _IEAttach, it doesn't look like you are using a valid IE object for the task. I'm guessing it's an embedded IE control? Such controls sometimes have security restrictions that don't allow you to manipulate things as you can with the IE application. I don't know if that prevents you from accessing the DOM elements. I have seen before (in an IE control embedded in a help file) where you cannot read the IE control's source, even if you navigate it to a valid web url. Have you tried _IEDocReadHTML on the control? If this is the case, I don't think there is a way around it.

Edit: If _IECreate works, can you not use it?

Edited by mikehunt114

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

Share this post


Link to post
Share on other sites

In the instance where you are using _IEAttach, it doesn't look like you are using a valid IE object for the task. I'm guessing it's an embedded IE control? Such controls sometimes have security restrictions that don't allow you to manipulate things as you can with the IE application. I don't know if that prevents you from accessing the DOM elements. I have seen before (in an IE control embedded in a help file) where you cannot read the IE control's source, even if you navigate it to a valid web url. Have you tried _IEDocReadHTML on the control? If this is the case, I don't think there is a way around it.

Edit: If _IECreate works, can you not use it?

I'll experiment with the DocReadHTML after it logs in, (which it does via the Attach.)

I'm using many different vb.net created browsers to get around the cookie issues, which was/is the problem from my previous topic today. (Here.)

I will be back momentarily with the results of IEDocReadHTML

Share this post


Link to post
Share on other sites

MsgBox(0, "IEDocReadTest", _IEDocReadHTML($oIE))

The above yields the full html of the page past the login, as expected.

Share this post


Link to post
Share on other sites

This returns nothing post login.

_FredLogIn()
MsgBox(0, "test", "Post Login, still working?")

$num = 0
    while 1
        MsgBox(0, "Test", "Inside While Loop.")
        If $num = 4 Then ExitLoop
        $oForm1 = _IEFormGetCollection ($oIE, 0)
        MsgBox(0,"Form", $oForm1)
        WEnd

Share this post


Link to post
Share on other sites

This returns nothing post login.

_FredLogIn()
MsgBox(0, "test", "Post Login, still working?")

$num = 0
    while 1
        MsgBox(0, "Test", "Inside While Loop.")
        If $num = 4 Then ExitLoop
        $oForm1 = _IEFormGetCollection ($oIE, 0)
        MsgBox(0,"Form", $oForm1)
        WEndoÝ÷ Ûú®¢×´ßª¢¹µÆ§¡¸ÞrÖ§w
'ßÛ]Êek*k¢«(§hË Z,Èò¢ìÛhv+)¬¬¢g­{m¯+^²Ø§Øb³²jëh×6$num = 0
    while 1
        MsgBox(0, "Test", "Inside While Loop.")
        If $num = 4 Then ExitLoop
        $oForm1 = _IEFormGetCollection ($oIE, $num)
        If IsObj($oForm1) Then
            MsgBox(0,"Form", "Form " & $num & " = " $oForm1.name)
        Else
            MsgBox(16,"Error", "Failed to get form " & $num)
        EndIf
        $num += 1
        WEnd

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Func _Fullbleed()
    
    $num = 0
    while 1
        MsgBox(0, "Test", "Inside While Loop.")
        If $num = 4 Then ExitLoop
        $oForm1 = _IEFormGetCollection ($oIE, $num)
        If IsObj($oForm1) Then
            MsgBox(0,"Form", "Form " & $num & " = " & $oForm1.name)
        Else
            MsgBox(16,"Error", "Failed to get form " & $num)
        EndIf
        $num += 1
 ;       WEnd
;~  $num = 0
;~  while 1
;~      If $num = 4 Then ExitLoop
        $oForm1 = _IEFormGetObjByName($oIE,0,1)
        $oSelect = _IEFormElementGetObjByName ($oForm1, "id")
        For $i = 1 To 1
        _IEFormElementOptionselect ($oSelect, $num, 1, "byIndex")
        Next
        $obutton1 = _IEFormElementGetObjByName($oForm1, "submit")
        $obutton1.click()
        _IELoadWait($oIE)
        _IENavigate($oIE,"www.xxxxx.net/d.php?id=" & $id)
        _IELoadWait($oIE)
        $oForm = _IEFormGetObjByname($oIE,"transact")
        $obutton = _IEFormElementGetObjByName($oForm, "submit")
        $obutton.click()
        _IELoadWait($oIE)
        _IENavigate($oIE,"www.xxxxxxnet/d.php?id=" & $id)
        _IELoadWait($oIE)
;~      $num = $num + 1
    WEnd
EndFunc

This did switch the form to the next character before erroring out. (perhaps .click is the problem.)

Share this post


Link to post
Share on other sites

I changed out $obutton for, _IEFormSubmit ($oForm1) still errors out of ie.au3:

>Running:(3.2.5.4):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\\SelectTest.au3"

--> IE.au3 V2.3-1 Warning from function _IELoadWait, $_IEStatus_AccessIsDenied (Cannot verify readyState. Likely casue: cross-site scripting security restriction.)

--> IE.au3 V2.3-1 Warning from function _IELoadWait, $_IEStatus_AccessIsDenied (Cannot verify readyState. Likely casue: cross-site scripting security restriction.)

C:\Program Files\AutoIt3\beta\Include\IE.au3 (1154) : ==> The requested action with this object has failed.:

$o_col = $o_object.document.forms.item ($s_Name)

$o_col = $o_object.document^ ERROR

->16:13:22 AutoIT3.exe ended.rc:1

+>16:13:23 AutoIt3Wrapper Finished

>Exit code: 1 Time: 29.045

It still switched characters in the form before blowing up however.

Share this post


Link to post
Share on other sites

Please see the remarks section of of _IEFormSubmit:

If you experience trouble with the automatic _IELoadWait called by default, please set $f_wait parameter to 0 and call _IELoadWait from your script, passing it the InternetExplorer object.

Without calling _IELoadWait($oIE) you may be trying to access an element before it is ready.

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

Please see the remarks section of of _IEFormSubmit:

Without calling _IELoadWait($oIE) you may be trying to access an element before it is ready.

Dale

while 1
        MsgBox(0, "Test", "Inside While Loop.")
        If $num = 4 Then ExitLoop
        $oForm1 = _IEFormGetCollection ($oIE, $num)
        If IsObj($oForm1) Then
            MsgBox(0,"Form", "Form " & $num & " = " & $oForm1.name)
        Else
            MsgBox(16,"Error", "Failed to get form " & $num) 
        EndIf ; returns " Form 0 = 0 "
        $oForm1 = _IEFormGetObjByName($oIE,0,1)
        If IsObj($oForm1) Then
            MsgBox(0,"Form", "Form " & $num & " = " & $oForm1.name)
        Else
            MsgBox(16,"Error", "Failed to get form " & $num)
        EndIf ; returns " Form 0 = 0 "
        $oSelect = _IEFormElementGetObjByName ($oForm1, "id")
        For $i = 1 To 1
        _IEFormElementOptionselect ($oSelect, $num, 1, "byIndex")
        Next
                _IEFormSubmit ($oForm1, 0)
        _IELoadWait($oIE)
        _IENavigate($oIE,"www.xxxxxxxx.net/d.php?id=" & $id)
        _IELoadWait($oIE)
        $oForm = _IEFormGetObjByname($oIE,"transact")
        _IEFormSubmit ($oForm, 0)
        _IELoadWait($oIE)
        _IENavigate($oIE,"www.xxxxx.net/dphp?id=" & $id)
        _IELoadWait($oIE)
        $num = $num + 1
    WEnd

Same results with $obutton and _IEFormSubmit. Errors immediately after switching to the next line in the form.

CODE
<form method="post" style="display:inline;">

<select name="id">

<option value="0000005485" SELECTED>Donna</option>

<option value="0000005486" >Jo</option>

<option value="0000005487" >Allison</option>

<option value="0000005488" >Lisa</option>

</select>

&nbsp;&nbsp;

<input type=submit value="switch profile" class="submit" name="submit">

</form>

Keep in mind this Only happens with the "IEAttach"

Share this post


Link to post
Share on other sites

It is not at all clear to me what you are trying to do and I have no idea what "switching to the next line of the form" means.

Can you simplify your scenario and description?

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 is not at all clear to me what you are trying to do and I have no idea what "switching to the next line of the form" means.

Can you simplify your scenario and description?

Dale

It is switching from 0 in the index, to 1.

<option value="0000005485" SELECTED>Donna</option> ; From this

<option value="0000005486" >Jo</option> ; To This.

<option value="0000005487" >Allison</option>

<option value="0000005488" >Lisa</option>

however, I just took out the $num =+ 1 so now it just errors where it Should be submitting the form.(I can navigate the form.. but I can't make it submit.) I have tried this without any ieloadwait's too. Same error on line 1154 of ie.au3.

P.S. Given the separate instances of IE you showed me how to create, this will be obsolete. Thank you for sticking with me anyhow though. =)

Share this post


Link to post
Share on other sites

Good. 'cause I was a long way from understanding what you were talking about.

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 is switching from 0 in the index, to 1.

however, I just took out the $num =+ 1 so now it just errors where it Should be submitting the form.(I can navigate the form.. but I can't make it submit.) I have tried this without any ieloadwait's too. Same error on line 1154 of ie.au3.

P.S. Given the separate instances of IE you showed me how to create, this will be obsolete. Thank you for sticking with me anyhow though. =)

I only inserted the $num += 1 increment because your loop in post #5 gave me the impression you were trying to step through form indexes 0 thru 3 and then exit when $num = 4.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I only inserted the $num += 1 increment because your loop in post #5 gave me the impression you were trying to step through form indexes 0 thru 3 and then exit when $num = 4.

:)

You're very correct, I used yours while testing, then reverted to adding it back at the end of the total While loop. For more testing. =) I understood what you did. Thank you again for the assistance.

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