我一直在欺骗试图让脚本工作以自动按钮按下。对于完整的新手来说,这不是一件容易的事,我可以向您保证。
这是上述按钮的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>
这是在特定框架内的代码深处嵌入的(我认为这是正确的术语(。
另一个线程中提供的此链接包含我需要的脚本,但是在我的情况下,我难以实施。
我尝试了这一点:
+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
运行代码后,我在...脚本...运行...查看.. window thick:
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实际上是"按钮",但这也是我尝试过的tagname,tagn name =" pirPropertiesContainer_componentnext_0",我尝试过将其更改为getElementByname,我尝试了许多排列。
我有一种感觉,因为我在工作中使用的系统的某些未知限制在代码的第一部分中迈出了一步,但是截至这一刻,我坚持了想法。至少可以说是我的深度!
我在某个线程中看到了我可能必须尝试创建一个循环以循环循环浏览元素以找到您想要的一个,但是...
下一步的任何帮助都很好!
欢呼
edit1:所讨论的网站是一个具有文档前端的Oracle数据库,也是基于Web的用户界面。它在工作中的Intranet上运行,并且似乎无法访问更广泛的互联网而没有连接到网络。
edit2:我已经尝试了更多的代码。我认为我最初的问题是我在错误的位置上的功能。一旦达到"返回WB",脚本就会结束。脚本的肉和脚本末尾的功能至少运行整个脚本!
" readystate =!4"段永远循环,所以我将其删除,并像wb.busy一样将其保留,它似乎每次都在运行。
仍然没有单击。因此,现在我想知道是否还有其他事情可以通过此Getelement业务来测试它正在工作。我已经提到了Focus((,并且我已经尝试了类似的负面结果。我猜这就像焦点?
我尝试了使用不同数字的按钮[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的方法:
+q::
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
}
}
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
MsgBox % wb.document.getElementByID("PierPropertiesContainer_componentnext_0").innerHTML ;// or innertext or outerHTML
wb.document.getElementByID("PierPropertiesContainer_componentnext_0").click() ;// is "button" the ID? No. Try the name, or use a different selector
return
注意,我添加了一些例程来确保IE页面已完成(对,对,它在打开选项卡中,但以防万一(。
如果您需要"按钮",则需要" tagName"选择器和[枚举]:
wb.document.getElementsByTagName("button")[3].click() ;// what number button is it?
编辑:在IEGET中添加了一个sgbox,以帮助诊断op
的问题请让我们知道您如何相处。。。