AutoHotKey JavaScript链接 [英] AutoHotKey JavaScript Link
问题描述
我不熟悉JavaScript和Web开发,因为我的经验主要是Java和C ++,因此我什至是新手.我正在使用AutoHotKey自动为我工作的公司输入数据,为了进入填写新项目的表格,我必须单击一个链接.当链接都具有href
值的URL时,我没有问题,但是现在我遇到了一个JavaScript链接,而且我不知道如何单击它……这是代码链接.
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,"ctl00_MainContent_view1Extender$0$ActionGroup$0","ActionGroup",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.
提前谢谢!
推荐答案
然后,有一种方法可以获取没有ID或Name的元素,但是一种简单的方法是遍历页面上的元素,直到找到您需要的那个.
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.
示例功能:
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
}
大多数时候.click()
方法都可以使用,但是在IE的最新版本中,我已经看到需要使用其他方法(例如dispatchEvent)来创建mouseevent对象
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
用法示例:
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
}
您也可以调用onclick事件正在执行的函数,但是先尝试一下,然后再根据需要尝试其他方法...
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...
希望有帮助
这篇关于AutoHotKey JavaScript链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!