Jump to content

Trying to click on IE link by classname


Recommended Posts

jZDhzUM.png

 

there's multiple classnames called "muted", but I want to click on the first one.

 

Here's what i'm trying to do:

 

#include <IE.au3>

;loads the site and inserts some text
Local $oIE = _IECreate("http://www.dba.dk/opret-annonce/#back")
Local $oForm = _IEFormGetCollection($oIE, 0)
Local $oQuery = _IEFormElementGetCollection($oForm, 1)
_IEFormElementSetValue($oQuery, "ur")
;~ _IEFormSubmit($oForm)

;clicks a button
Local $oSubmit = _IEGetObjByName($oIE, "Find kategori")
_IEAction($oSubmit, "click")


;----------------------------------------------------------

$oElems = _IETagNameGetCollection($oIE, "li") ; get all li tags
For $oElem In $oElems ; loop over all elements
    If StringInStr($oElem.className, "muted") Then ; this is the tag we need
        $oLink = _IETagNameGetCollection($oIE, "a", 0) ; get the first link inside the element
        _IEAction($oLink, "click") ; click the link
        ExitLoop
    EndIf
Next

I can't get the last part to work, maybe someone has a suggestion?

Link to comment
Share on other sites

From what I can see, this part is broken

Local $oSubmit = _IEGetObjByName($oIE, "Find kategori")
_IEAction($oSubmit, "click")

but can easily be fixed by replacing with

_IEFormSubmit($oForm)

Also, this

$oLink = _IETagNameGetCollection($oIE, "a", 0) ; get the first link inside the element

returns the first link on the page. Perhaps you meant this instead?

$oLink = _IETagNameGetCollection($oElem, "a", 0) ; get the first link inside the element

 

Link to comment
Share on other sites

This works for me --

#include <IE.au3>

;loads the site and inserts some text
Local $oIE = _IECreate("http://www.dba.dk/opret-annonce/#back")
Local $oForm = _IEFormGetCollection($oIE, 0)
Local $oQuery = _IEFormElementGetCollection($oForm, 1)
_IEFormElementSetValue($oQuery, "ur")

Sleep(2000)

$oElems = _IETagNameGetCollection($oIE, "li") ; get all li tags

For $oElem In $oElems ; loop over all elements
    If StringInStr($oElem.className, "muted") Then ; this is the tag we need
        ConsoleWrite("found!" & @CRLF)
        $oLink = _IETagNameGetCollection($oElem, "a", 0) ; get the first link inside the element
        _IEAction($oLink, "click") ; click the link
        ExitLoop
    EndIf
Next

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...