Jump to content

Click div with <a onclick


Recommended Posts

Hello community,

I've got following code (I refresh the Hwnd everytime - not the problem)

$oIE = _IEAttach("0x00050472", "HWND")

$aArray = _IEGetObjByClass($oIE, "classname", "div")
$o = $aArray[3]
;Click $o

Func _IEGetObjByClass($oIE, $sClass, $sTag = "*")
    Local $aRet[1] = [0]

    Local $allHTMLTags = _IETagNameGetCollection($oIE, $sTag)
    For $o In $allHTMLTags
        If IsString($o.className) And $o.className = $sClass Then
            $aRet[0] += 1
            ReDim $aRet[$aRet[0] + 1]
            $aRet[$aRet[0]] = $o
        EndIf
    Next

    Return $aRet
EndFunc   ;==>_IEGetObjByClass

and this is the html code

<span id="someNumbers">
    <div title="title_something" class="classname" style="padding: 0px 5px;">
        <a onclick=" javascript:someJob(id, this); ">Text</a>
    </div>
</span>

$o.innerText is giving me "Text" and anyway I have no problems to get the values.

My problem is that I cannot click this span/div.

I tried:

1. Open javascript:OrdersType(id, this) with _IENavigate

2. fireEvent("whatever you can do with fireEvent")

3. _IEAction

I cannot use the id of the span because its variable like everything else. The only static thing is the text between the <a></a> tags.

The span is generated dynamically so I cannot find it in the regular source code when using IE. With _IEBodyReadHTML I see the source code like it has to be.

How can I click that span?

Thanks in advance.

JimmyBeam

Edited by JimmyBeam
Link to comment
Share on other sites

There are pleanty of ways with the _IE functions.

You can use my signature to use xpath to grab the IEdom object by xpath...example

; full
$yourXpath = "//span[contains(@id,'somethingContainedWithin')]/div[@title='title_something']/a"

; alternate
$yourXpath = "//span[@id='someNumbers']//a[.='Text']"

; simple, if only link with text:
$yourXpath = "//a[.='Text']"
$aObjects = BGe_IEGetDOMObjByXPathWithAttributes($oIE, $yourXpath)
_IEAction($aObjects[0], "Focus")
_IEAction($aObjects[0], "Click")



If you absolutly need to click the span, then do this:

_IEAction($aObjects[0].parentNode.parentNode, "Click")
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Damn, you're good. Works brilliant. Thanks :)

Worked for me:

$yourXpath = "//a[.='Text']"
    $aObjects = BGe_IEGetDOMObjByXPathWithAttributes($oIE, $yourXpath)
        _IEAction($aObjects[0], "Focus")
        _IEAction($aObjects[0], "Click")
Edited by JimmyBeam
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...