我需要访问一个网站,然后选择原因并点击一个按钮。由于我有多个变量(原因),因此需要多次执行此操作,以便为每个变量创建一个报告。该网页的网址和标题相同,因为该网页是一种表单。
到目前为止,我已经创建了以下代码:
WB := ComObjCreate("InternetExplorer.Application")
WB.Visible:=True
wb.Navigate("http://url")
wb.document.title := "cause 1"
WinMaximize, % "ahk_id " wb.HWND
; Wait for page to load:
While wb.Busy or wb.ReadyState != 4
Sleep, 100
wb.document.getElementsByName("id_cause")[0].value := 1
wb.document.getElementsByName("btnSearch")[0].Click()
wb.Navigate("http://url", 2048)
wb.document.title := "cause 2"
While wb.Busy or wb.ReadyState != 4
Sleep, 100
wb.document.getElementsByName("id_cause")[0].value := 2
wb.document.getElementsByName("btnSearch")[0].Click()
return
正如我所期望的,所有命令都引用第一个选项卡。因此,第一个选项卡被重命名为原因1,而在此名称被重命名之后,再次被原因2为。 在网络上搜索解决方案时,我已经看到一些允许用户引用选项卡的代码,但是所有代码都使用URL来区分选项卡。
在这种情况下(相同的URL),有没有办法实现我的目的?我在考虑诸如标签索引或重命名URL并将命名用于标识的事情。
我在网上找到的代码之一是:
navOpenNewForegroundTab = 65536
navOpenInBackgroundTab = 4096
navOpenInNewWindow = 1
navOpenInNewTab = 2048
wb := ComObjCreate("InternetExplorer.Application") ; create a IE instance
IeHwnd := wb.Hwnd
wb.Visible := True
wb.Navigate("Google.com")
While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
Sleep, 10
wb.Navigate("DuckDuckgo.com", navOpenInNewTab)
while !wb2
wb2 := New_IE("DuckDuckgo.com")
wb2.Navigate("Google.com")
While wb2.readyState != 4 || wb2.document.readyState != "complete" || wb2.busy ; wait for the page to load
Sleep, 10
wb.Navigate("DuckDuckgo.com", navOpenInNewTab)
while !wb3
wb3 := New_IE("DuckDuckgo.com")
wb3.Navigate("Google.com")
While wb3.readyState != 4 || wb3.document.readyState != "complete" || wb3.busy ; wait for the page to load
Sleep, 10
Msgbox then just use wb or wb2 or wb3 to control tab1, tab2 or tab3`n`nFor Example lets look up something in tab 2 now...
Something_to_look_for := "duckduckgo"
wb2.Navigate("Google.com/#q=" Something_to_look_for)
While wb2.readyState != 4 || wb2.document.readyState != "complete" || wb2.busy ; wait for the page to load
Sleep, 10
return
New_IE(Url) {
For wb in ComObjCreate("Shell.Application").Windows
{
If instr( wb.LocationUrl, URL) && InStr( wb.FullName, "iexplore.exe" )
return wb
else
continue
}
}
答案 0 :(得分:0)
IEGetN()是一项功能,它将为您提供具有指定标题的第n个IE窗口。该窗口必须已经打开。
您可以这样使用它:
wb1 := IEgetN("Google",1)
wb5 := IEgetN("Google",5)
功能如下:
IEGetN(name="",_n=1)
{
_counter = 1
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")
{
if (_counter ==_n)
{
return wb
}
_counter += 1
}
}