【发布时间】:2018-09-08 08:47:18
【问题描述】:
我一直在胡闹,试图让脚本自动按下按钮。我可以向你保证,对于一个新手来说,这不是一件容易的事。
这是该按钮的html代码:
<div class"rightButtonSection">
<button name="PierPropertiesContainer_componentnext_0" title="Next Page" class="button buttonLink" onclick"setKeys(event);__xee72onclick(this);" type="button">Next</button>
</div>
这在代码中嵌入了很深的特定框架内(我认为这是正确的术语)。
在另一个线程中提供的this link 包含我需要的脚本,但在我的情况下,我无法实现它。
我的尝试做到了这一点:
+q::
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
}
wb := IEGet("Webtop - Internet Explorer")
wb.Visible := true
wb.document.getElementByID("button").click() ;// is button the ID? try the name or a different selector
return
运行代码后,我在...脚本...运行...查看..窗口中得到了这个:
001: Return (19.94)
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.11)
007: if wb.LocationName=Name && InStr(wb.FullName, "iexplore.exe")
007: if wb.LocationName=Name && InStr(wb.FullName, "iexplore.exe")
009: } (3.21)
如果我理解正确的话,我怀疑,它似乎已经捕获了我的两个正在运行的 IE 实例,但这是努力所能得到的。
但是!我刚刚在脚本查看窗口的视图下拉菜单中发现了“变量及其内容”选项,上面写着:
0[1 of 3]: 0
ErrorLevel[1 of 3]: 0
wb[0 of 0]:
这有点令人担忧,有点暗示它根本没有找到任何东西可以放入 wb。
我不知道如何复制windowspy的内容,但最上面的标题窗口框写着:
Webtop - Internet Explorer
ahk_class IEFrame
ahk_exe iexplore.exe
我认为elementID实际上是“按钮”,但这也是标记名,我尝试过的按钮名称="PierPropertiesContainer_componentnext_0",我尝试将其更改为getElementByName,我尝试了许多排列。
我有一种感觉,因为我在工作中使用的系统的一些未知限制正在影响代码的第一部分中的一个步骤,但到目前为止,我一直在寻找想法。至少可以说超出了我的深度!
我在某个线程中看到我可能不得不尝试创建一个循环来循环遍历元素以找到您想要的元素,但是......
对下一步的任何帮助都会很棒!
干杯
编辑1: 有问题的站点是一个带有文档前端和基于 Web 的用户界面的 Oracle 数据库。它在工作时在 Intranet 上运行,并且在没有连接到网络的情况下似乎无法访问更广泛的 Internet。
编辑2: 我已经尝试过更多地弄乱代码。我认为我最初的问题是我把函数放在了错误的地方;一旦它点击“返回 wb”,脚本就会结束。前面有脚本的内容,脚本末尾的函数,它至少运行了整个脚本!
“ReadyState =! 4”段永远循环,所以我删除了它并将其保留为 while wb.busy,它似乎每次都在运行。
仍然没有点击。所以现在我想知道我是否可以对这个 getElement 业务做些什么来测试它是否正常工作。我已经看到 focus() 被提及,并且我已经尝试过类似的负面结果。我猜这就像标签焦点?
我尝试了不同数字的 button[5] 方法,但遗憾的是这也无效。
我的直觉告诉我 wb.document.getElementByName 是要走的路,因为代码显示“
编辑 3: 这是我的代码的当前状态(“重新加载”也派上用场了):
+q::
wb := IEGet("Webtop") ;// call to IEGet function passing the IE tab name as a parameter to assign the tab to a wb object
wb.Visible := true
while wb.busy or wb.ReadyState != 4 ;// make sure page is fully loaded
Sleep 150
document.getElementsByTagName("button")[1].focus()
;// is "button" the ID? No. Try the name, or use a different selector
return
IEGet(name="") { ;//IEGet is a function. It returns a wb object
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")
{
;MsgBox % "Found it! (" . wb.FullName . ")" ; for debugging (comment out when done)
return wb
}
}
f6::
reload
return
编辑 4
此时我几乎放弃了选择我所追求的元素。似乎是因为该网站正在运行一些超出我理解能力的 JAVA 业务,因此该按钮在表面上不存在,因此 AHK 看不到它。
我的解决方案是专注于 AHK 可以看到的一个元素(标题),然后多次按 shift+tab,直到找到我想要按下的按钮。
这里的致命缺陷是,如果移动标签/按钮位置发生任何变化,它将不起作用。所以至少可以说有点喜怒无常。我徒劳地进行了像素颜色检查,希望像素位置在每个人的 UI 中保持一致,只是为了有某种故障保护措施来阻止自动化进行疯狂的杀戮。
f6::
wb := IEGet("Webtop") ;// call to IEGet function passing the IE tab name as a parameter to assign the tab to a wb object
wb.Visible := true
while wb.busy ;or wb.ReadyState != 4 ;// make sure page is fully loaded
Sleep 150
loop 4
{
PixelGetColor, color, 145,145
;msgbox %color%
if color <> 0x9D663B
break
wb.Document.all(1).focus()
if A_index = 4
{
send +{tab 7}
send {enter}
break
}
send +{tab 5}
send {enter}
while wb.busy
sleep 150
}
return
IEGet(name="") { ;//IEGet is a function. It returns a wb object
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")
{
;MsgBox % "Found it! (" . wb.FullName . ")" ;for debugging (comment out when done)
return wb
}
}
【问题讨论】:
-
哎呀,第一件事是你还在使用 IEGet 错误。 IEGet 返回您的 wb。我会把它放在一个答案中,让我们知道其余的是否好。 . .
标签: java html autohotkey