Jump to content
Sign in to follow this  

IE.au3 LinkClick

Recommended Posts

I'm not sure if DaleHohm has considered this before or not:

I was writing a utility which made use of the fabulous ie.au3 library. I needed to click a link based on URL.

As it stands now, you need to manually iterate each link using _IELinkGetCollection, and then switch to _IELinkClickByIndex to make the click. It's an involved process, when comparised to _IELinkClickByText which does it all in one command.

It would be good if link clicks could be generalized. So throw away _IELinkClickByText, and replace it with:

_IELinkClickByType (or whatever you want to call it).

It could have the form:

_IELinkClickByType( ByRef $o_object, $s_linkString, $s_mode = "text" , [$f_wait = 1]] )

$s_linkString = the string to match

$s_mode = "text", "URL", etc.

I've bastardized the format of some already existing _IE commands, here. The concept being that you can cause a link click as easily base on URL (or any other relevant criteria) as you can now on text.

Share this post

Link to post
Share on other sites

What would be the point of clicking a link by url? Why not just navigate to it. :whistle:

Easy. I have a tv site which I parse. On the TV guide page, it has links to individual page descriptions about episodes. Now, all description links contain a certain substring within a javascript URL. The link changes for every episode. However, there is always a substring that contains a unique string that I know about.

So, I need to be able to say, click on the link that contains "blah blah" in its URL.

And in case you're thinking that you can just calculating the URL, the site has referer blockers, so you HAVE to click to its pages from the main TV guide page. You can't go straight to its description pages.

Share this post

Link to post
Share on other sites

Something like this?

#include <IE.au3>

$sURL = "www.google.com"
$oIE = _IECreate($sURL)

_IEClickLinkByURL($oIE, "services")

Func _IEClickLinkByURL(ByRef $o_object, $s_linkURL, $i_index = 0, $f_wait = 1)
    If Not IsObj($o_object) Then
        __IEErrorNotify ("Error", "_IELinkClickByURL", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    Local $found = 0, $link, $linkURL, $links = $o_object.document.links
    $i_index = Number($i_index)
    For $link In $links
        $linkURL = $link.href
        If StringInStr($linkURL, $s_linkURL) Then
            If ($found = $i_index) Then
                If $f_wait Then
                    Return -1
                Return -1
            $found = $found + 1
    __IEErrorNotify ("Warning", "_IELinkClickByURL", "$_IEStatus_NoMatch")
    SetError($_IEStatus_NoMatch) ; Could be caused by parameter 2, 3 or both
    Return 0
EndFunc   ;==>_IEClickLinkByURL

Share this post

Link to post
Share on other sites

I'll admit I've thought about this. There are a couple of functions that could be redesigned to make them more generic like this. In the end I based my decision on watching the usage pattern (based on questions in the forum and examples posted) and decided that the way those functions were designed today met the need and were easy to use -- I've gotten almost no questions about _IELinkClickByText and it is used in a large percentagte of scripts written with IE.au3.

As you mention, the functionality is readily available now by iterating through the links collection.

Thanks, but for now I choose to leave it as it is.


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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...