AutoHotKey JavaScript Link

泄露秘密 提交于 2019-12-24 13:20:35

问题


I'm not familiar with JavaScript and web development, as my experience is in Java and C++ primarily, and I'm even new to that. I'm using AutoHotKey to automate data entry for the company I work for, and in order to get into the form that to fill out a new item, I have to click a link. I've had no problem when the links all had URLs for href values, but now I'm running into one that is a JavaScript link, and I don't know how to click it... here is the code for the link.

<a href="javascript:" 
tabindex="7"
onclick="this.parentNode.parentNode._skip=true;$find('ctl00_MainContent_view1Extender').executeAction('ActionBar',0,null,0);return false;"
onfocus="$showHover(this,&quot;ctl00_MainContent_view1Extender$0$ActionGroup$0&quot;,&quot;ActionGroup&quot;,2)" 
title="New Reimbursement" 
onblur="$hideHover(this)">New Reimbursement</a>

And I'm not sure what to do with it, despite a days worth of Googling.

Thanks in advance!


回答1:


More then one way get to an element without a ID or Name, but one of the easy ones are to loop over the elements on the page until you get to the one you need.

Example Function:

LoopElements(Elements, String, attribute="title")
{
try
Loop % Elements.Length ; check each element
    If instr((Elements[A_Index-1])[Attribute], String) ; if the Attribute text is what we need
        return Elements[A_Index-1] ; return Element
}

Most of the time the .click() method will work but with the newest versions of IE I have seen a need to use other methods like dispatchEvent to make a mouseevent object

Usage example:

site := "ahkscript.org"

wb := ComObjCreate("InternetExplorer.Application")
wb.visible := true
wb.navigate(site)

while wb.readyState!=4 || wb.document.readyState != "complete" || wb.busy
    continue

links := wb.document.getElementsByTagName("A")

linkElement := LoopElements(links, "GNU General Public License", "innertext")

if (linkElement)
{
    msgbox % "Element found it was #" linkElement.sourceindex "`n`nLets click it!"
    linkElement.click()
}
else
    msgbox % "no Element found"
return



LoopElements(Elements, String, attribute="title")
{
try
Loop % Elements.Length ; check each element
    If instr((Elements[A_Index-1])[Attribute], String) ; if the Attribute text is what we need
        return Elements[A_Index-1] ; return Element
}

You can also call the function the onclick event is doing but try this first then later you can try other ways as you get the need...

Hope it helps



来源:https://stackoverflow.com/questions/27371726/autohotkey-javascript-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!