AHK 网页元素按钮按下
AHK web element button press
我一直在尝试了解如何让 AHK 按下按钮而不是通过图像或像素搜索,或者通过坐标,而是通过网络元素 ID,这样它就可以在不同的 PC 上工作,而无需问题,并且不太容易失败。
我已经确定了按钮的网络代码:
<div class"rightButtonSection">
<button name="PierPropertiesContainer_componentnext_0" title="Next Page" class="button buttonLink" onclick"setKeys(event);__xee72onclick(this);" type="button">Next</button>
</div>
我在这里有点不知所措,而且我从来没有在网上找到对 AHK 有很大帮助的指南。
我认为这将与 document.getElementById("button") 有关,这是我目前所了解的。
如果您知道我下一步可以尝试什么或我需要什么额外信息,请告诉我!
干杯
编辑:
根据 link 和感激地提供的建议,我把这些放在一起:
!q::
IEGet(name="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
for wb in ComObjCreate("Shell.Application").Windows()
if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
return wb
}
wb := IEGet()
wb.Visible := true
wb.document.getElementById("button").click()
return
遗憾的是,这仍然没有任何作用,但我觉得它越来越接近了。
编辑2:
IEGET(name="") 位似乎在工作,它将循环遍历所有打开的选项卡,它看起来像。但是一旦它点击 'return, wb' 它就挂在那里,所以错误一定是我识别标签名称......也许......
001: Return (3.37)
004: if name =
004: WinGetTitle,name,ahk_class IEFrame
005: name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
006: For wb, in ComObjCreate("Shell.Application").Windows() (0.09)
007: if wb.LocationName=Name && InStr(wb.FullName, "iexplore.exe")
008: Return,wb (4.82)
Press [F5] to refresh.
看@Michael_Curry评论。您需要创建一个包含 Web 浏览器对象 (Internet Explorer) 的 AHK 对象。这是创建一个的简单脚本:
wb := ComObjCreate("InternetExplorer.Application") ;// Create an IE object
wb.Visible := true ;// Make the IE object visible
wb.Navigate("www.AutoHotkey.com") ;// Navigate to a webpage
那么,您的代码将按如下方式工作:
wb.document.getElementById("button")
编辑每条评论:
如果您需要找到一个已打开的 IE 选项卡用作您的 wb 对象,请将第一行替换为:
IEGet("The name of the IE tab you want to use")
并将以下 IEGet 函数(来自 link)添加到您的脚本中:
IEGet(name="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ;// Get active window if no parameter
Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
for wb in ComObjCreate("Shell.Application").Windows()
if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
return wb
}
根据 OP 的合理尝试进行编辑
你快到了。您需要将 IE 选项卡名称放在引号中,并且可能有助于使用选择器(但这是另一个问题)。尝试:
wb := IEGet("IE tab name") ;// here put in the actual IE tab name in quotes
wb.Visible := true
wb.document.getElementById("PierPropertiesContainer_componentnext_0").click() ;// is button the ID? try the name or a different selector
Hth,
getElementbyID 在这种情况下不起作用,因为您的对象中没有名为 "ID" 的元素。您将不得不通过另一个选择器 "grab" 它 - class 或键入,最有可能。可悲的是,我和你在同一条船上有 javascript 的对象,所以除了尝试 getElementsbyClassName 或循环遍历这种类型的所有对象并找到它在哪个数字上,我没有答案给你页面并以这种方式选择它。祝你好运!
我一直在尝试了解如何让 AHK 按下按钮而不是通过图像或像素搜索,或者通过坐标,而是通过网络元素 ID,这样它就可以在不同的 PC 上工作,而无需问题,并且不太容易失败。
我已经确定了按钮的网络代码:
<div class"rightButtonSection">
<button name="PierPropertiesContainer_componentnext_0" title="Next Page" class="button buttonLink" onclick"setKeys(event);__xee72onclick(this);" type="button">Next</button>
</div>
我在这里有点不知所措,而且我从来没有在网上找到对 AHK 有很大帮助的指南。
我认为这将与 document.getElementById("button") 有关,这是我目前所了解的。
如果您知道我下一步可以尝试什么或我需要什么额外信息,请告诉我!
干杯
编辑:
根据 link 和感激地提供的建议,我把这些放在一起:
!q::
IEGet(name="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
for wb in ComObjCreate("Shell.Application").Windows()
if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
return wb
}
wb := IEGet()
wb.Visible := true
wb.document.getElementById("button").click()
return
遗憾的是,这仍然没有任何作用,但我觉得它越来越接近了。
编辑2:
IEGET(name="") 位似乎在工作,它将循环遍历所有打开的选项卡,它看起来像。但是一旦它点击 'return, wb' 它就挂在那里,所以错误一定是我识别标签名称......也许......
001: Return (3.37)
004: if name =
004: WinGetTitle,name,ahk_class IEFrame
005: name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
006: For wb, in ComObjCreate("Shell.Application").Windows() (0.09)
007: if wb.LocationName=Name && InStr(wb.FullName, "iexplore.exe")
008: Return,wb (4.82)
Press [F5] to refresh.
看@Michael_Curry评论。您需要创建一个包含 Web 浏览器对象 (Internet Explorer) 的 AHK 对象。这是创建一个的简单脚本:
wb := ComObjCreate("InternetExplorer.Application") ;// Create an IE object
wb.Visible := true ;// Make the IE object visible
wb.Navigate("www.AutoHotkey.com") ;// Navigate to a webpage
那么,您的代码将按如下方式工作:
wb.document.getElementById("button")
编辑每条评论:
如果您需要找到一个已打开的 IE 选项卡用作您的 wb 对象,请将第一行替换为:
IEGet("The name of the IE tab you want to use")
并将以下 IEGet 函数(来自 link)添加到您的脚本中:
IEGet(name="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ;// Get active window if no parameter
Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
for wb in ComObjCreate("Shell.Application").Windows()
if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
return wb
}
根据 OP 的合理尝试进行编辑
你快到了。您需要将 IE 选项卡名称放在引号中,并且可能有助于使用选择器(但这是另一个问题)。尝试:
wb := IEGet("IE tab name") ;// here put in the actual IE tab name in quotes
wb.Visible := true
wb.document.getElementById("PierPropertiesContainer_componentnext_0").click() ;// is button the ID? try the name or a different selector
Hth,
getElementbyID 在这种情况下不起作用,因为您的对象中没有名为 "ID" 的元素。您将不得不通过另一个选择器 "grab" 它 - class 或键入,最有可能。可悲的是,我和你在同一条船上有 javascript 的对象,所以除了尝试 getElementsbyClassName 或循环遍历这种类型的所有对象并找到它在哪个数字上,我没有答案给你页面并以这种方式选择它。祝你好运!