Search code examples
autoit

Autoit - searching for a URL in a web page and click on it


I'm trying to figure out how can I click a URL that matches a specific pattern. For example:

#include <IE.au3>
#include <MsgBoxConstants.au3>

local $pattern = "/123/"
Local $oIE = _IECreate("www.example.com",0,1,1,1)
Local $oLinks = _IELinkGetCollection($oIE)

For $oLink In $oLinks

    If StringInStr($oLink, $pattern)  Then
        _IEAction($oLink, "click")
        sleep(700)
        _IEQuit($oIE)
        ExitLoop
    EndIf
Next

Basically what I need to achieve is, if a $oLink in $oLinks contains $pattern - click on it. The above program, for some reason, does not work.

Any suggestions?

Thank you


Solution

  • I'm not sure if you can use StringInStr on the object.

    Try using:

    StringInStr($oLink.href, $pattern)
    

    instead.