Sign in to follow this  
Followers 0
bzh

Get Object variable

9 posts in this topic

Hi,

I'm starting to make script with AutoIt and I got one problem:

In a new IE page created with _IECreate() function , I simulate a click on a link with the function _IELinkClickByText(). This command works fine for the first time.

The new page opens in the same window with the new url. When I try to click on other link with _IELinkClickByText() function in the new page, the script is blocked at this step ;) . I guess that it comes from the object variable of the new window that is not recognized but I can't find the solution.

If anyone got the the solution......

Here a part of my script:

$oIE = _IECreate($url,0,1,1,-1)

_IELoadWait ($oIE)

$oIE = clickLinkByText($oIE,$link1)

$oIE = clickLinkByText($oIE,$link2)

$oIE = clickLinkByText($oIE,$link3)

; write data in a log file

Func writeLogFile($logFile,$logText)

$nbLines = _FileCountLines($logfile)

_FileWriteToLine($logFile, $nbLines+1, $logText)

EndFunc

; get the frames of the current window and click the link

Func clickLinkByText($windowID,$link)

Local $linkFound = "0", $val = ""

If _IEIsFrameSet($windowID) Then

; get the list of the frames

$oFrames = _IEFrameGetCollection ($windowID)

$iNumFrames = @extended

; for each frame, get all links and check that $link is present. Exit loop in this case

For $i = 0 to ($iNumFrames - 1)

$oFrame = _IEFrameGetCollection ($windowID, $i)

errorMgt($oFrame, "_IEFrameGetCollection()")

$oLinks = _IELinkGetCollection ($oFrame)

errorMgt($oLinks, "_IELinkGetCollection()")

$iNumLinks = @extended

For $oLink In $oLinks

If $oLink.outerText = $link Then

$val = $oLink.href

$result = _IELinkClickByText ($oFrame, $link)

$windowID = _IEAttach ($val,"url")

errorMgt($result, "_IELinkClickByText()")

; exit loop

$linkFound = "1"

exitLoop

EndIf

Next

If $linkFound == "1" Then

ExitLoop

EndIf

Next

EndIf

;Return $val

Return $windowID

EndFunc

Func errorMgt($result, $function)

If $result == 0 Then

Switch @error

Case 1 $msg = "General Error"

Case 3 $msg = "Invalid Data Type"

Case 4 $msg = "Invalid Object Type"

Case 6 $msg = "Load Wait Timeout"

Case 7 $msg = "No Match"

Case 8 $msg = "Access Is Denied"

Case Else $msg = "No error"

EndSwitch

writeLogFile($logFile,"errorMgt(): " & $msg)

Exit

EndIf

EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here a part of my script:

$oIE = _IECreate($url,0,1,1,-1)

_IELoadWait ($oIE)

$oIE = clickLinkByText($oIE,$link1)

$oIE = clickLinkByText($oIE,$link2)

$oIE = clickLinkByText($oIE,$link3)

You start out with $oIE being an IE object variable, then you turn it into I don't what with that clickLinkByText function...why not use the UDF included in IE.au3?

It should look more like:

$oIE = _IECreate($url, 0) ; The rest of the settings you chose are defaults anyways
; IELoadWait isn't necessary, it's already specified in IECreate
_IELinkClickByText($oIE, $link1)
_IELinkClickByText($oIE, $link2)
_IELinkClickByText($oIE, $link3)

That should help, but without more information from you, it's just a guess really.

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

Thank you for your help although my problem is not resolved !

I made the clickLinkByText(object,link) function because my window has x frames in it. This function search the link in all frames of the windows and stops as soon as the link is found.

The script works fine for link1 but is blocked just after the line "$result = _IELinkClickByText ($oFrame, $link)" for link2. link3 is not treated at all. In don't understand how $oIE is managed and how _IEAttach() is used...can you explain me please ! ;)

I'm looking for an example of a script with the use of _IELinkClickByText() many times in different windows

$oIE = _IECreate($urlPlanFi,0,1,1,-1)
clickLinkByText($oIE,$link1)
clickLinkByText($oIE,$link2)
clickLinkByText($oIE,$link3)

;Functions

Func clickLinkByText($windowID,$link)
    
    Local $linkFound = "0", $val = ""
    
    If _IEIsFrameSet($windowID) Then

        $oFrames = _IEFrameGetCollection ($windowID)
        $iNumFrames = @extended

        For $i = 0 to ($iNumFrames - 1)
            $oFrame = _IEFrameGetCollection ($windowID, $i)
            $oLinks = _IELinkGetCollection ($oFrame)
            $iNumLinks = @extended
            For $oLink In $oLinks
                If $oLink.outerText = $link Then
                    $val = $oLink.href
                    $result = _IELinkClickByText ($oFrame, $link)

                    $linkFound = "1"
                    exitLoop
                EndIf
            Next
        
            If $linkFound == "1" Then
                ExitLoop
            EndIf
        Next
    EndIf

EndFunc

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Could you grab the name of the frames, or use indexing, and then use _IELinkClickByText? I don't quite understand what you mean by "my window has x frames in it". Can you provide an url or source?

As for how $oIE is managed, it's all in the helpfile. When you define $oIE as an IECreate, you are creating an object variable representing the IE application or window. IEAttach is used to assign a given IE to an object variable in your script.

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

To further what mikehunt114 is asking, what is the result of the second link click? If it is displaying an alert box it could be the source of your trouble. Also, are all of the frames in the same domain? You could be running into a cross-domain security restriction.

Another comment... in the statement

If $oLink.outerText = $link Then

you should change to

If String($oLink.outerText) = $link Then

to avoid an emplty string from returning numeric 0 and causing the comparison to always evaluate to True.

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

Ok, I take this example that gives the same problem.

The script connect to the website http://www.bretagne.iufm.fr and simulates a mouse click on link1 (image named "Plan du site") on the current page, a mouse click on link2 (Link named "Annuaire") on the new page, and a mouse click on the link3 (Link named "FLEURY Norbert") on the last page opened.

Link1 and link2 are successfully opened but link3 is not opened. Where's my problem ??

Here the simple script:

#include <IE.au3>
#include <Array.au3>
#include <File.au3>

Local $count, $url = "http://www.bretagne.iufm.fr", $link1 = "http://www.bretagne.iufm.fr/images/b-plan-site.gif", $link2 = "Annuaire", $link3="FLEURY Norbert"
Local $linkFound, $val = ""

$oIE = _IECreate($url,0,1,1,-1)

$oImgs = _IEImgGetCollection($oIE)
For $oImg In $oImgs
    If String($oImg.src) == $link1 Then
        _IEImgClick ($oIE,String($oImg.src), "src")
        exitLoop
    EndIf
Next

$linkFound = 0

$oFrames = _IEFrameGetCollection ($oIE)
$iNumFrames = @extended
For $i = 0 to ($iNumFrames - 1)
    $oFrame = _IEFrameGetCollection ($oIE, $i)
    $oLinks = _IELinkGetCollection($oFrame)
    $iNumLinks = @extended
    For $oLink In $oLinks
        If String($oLink.outerText) == $link2 Then
            _IELinkClickByText ($oFrame,String($oLink.outerText))
            $linkFound = 1
            exitLoop
        EndIf
    Next
    
    If $linkFound == 1 Then
        ExitLoop
    EndIf
Next

$linkFound = 0

$oFrames = _IEFrameGetCollection ($oIE)
$iNumFrames = @extended
For $i = 0 to ($iNumFrames - 1)
    $oFrame = _IEFrameGetCollection ($oIE, $i)
    $oLinks = _IELinkGetCollection($oFrame)
    $iNumLinks = @extended
    For $oLink In $oLinks
        If String($oLink.outerText) == $link3 Then
            _IELinkClickByText ($oFrame,String($oLink.outerText))
            $linkFound = 1
            exitLoop
        EndIf
    Next
    
    If $linkFound == 1 Then
        ExitLoop
    EndIf
Next

Share this post


Link to post
Share on other sites

I'm still blocked with my problem explained previously..... ;)

Am I wrong if I use the following code to get the object of the currently active window ?

[autoit]

opt('WinTitleMatchMode',4)

$oIENew = _IEAttach("active","")

_IELoadWait($oIENew)

If not isObj($oIENew) Then

$errmsg = StringFormat("Not an object %s", @ERROR)

MsgBox(0, "Error", $errmsg)

EndIf

$oFrames = _IEFrameGetCollection ($oIENew)

....

[autoit]

Got an idea ?? :lmao:

Share this post


Link to post
Share on other sites

$oIENew = _IEAttach("active","")

will try to attach to a browser window with a main document title of "active" -- I'm guessing that is not what you want. None of the opt() values have any bearing on IE.au3 commands.

Suggest you reread the documentation for _IEAttach

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

Regarding the prior post, your FRAME drilling logic is not handling the case that FRAMESETs are nested inside FRAMEs. You'll need to make your logic recursive, checking is there are frames inside frames.

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