找回密码
 加入
搜索
查看: 4201|回复: 9

[AU3基础] 如何点击已经打开的某个window里的链接【已解决】

[复制链接]
发表于 2011-11-1 14:44:35 | 显示全部楼层 |阅读模式
本帖最后由 墙角那只猫 于 2011-11-2 14:38 编辑

如题:
我如何点击已经打开的某个window里的链接呢?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-11-1 14:46:06 | 显示全部楼层
以下是关于这个window的信息

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-11-1 14:49:11 | 显示全部楼层
用这段代码可以点击到,但我想要的是这个窗口已经由其他程序打开了,然后再去点击这个链接,应该怎么写呢?

#include <IE.au3>
$oIE = _IECreate ("http://172.16.29.21:9080/insurance/loginPage.do?pageName=loginPage")
Sleep(2000)
_IELinkClickByText ($oIE,"Continue to this website (not recommended).")
发表于 2011-11-1 15:44:08 | 显示全部楼层
$oIE = _IEAttach("http://172.16.29.21:9080/insurance/loginPage.do?pageName=loginPage", "url")
_IELinkClickByText ($oIE,"Continue to this website (not recommended).")
发表于 2011-11-1 15:44:28 | 显示全部楼层
函数参考
_IEAttach
--------------------------------------------------------------------------------

附加到指定的 Internet Explorer 实例,基于您所选择的模式按照字符串/子字符串匹配.


#include <IE.au3>
_IEAttach ( $s_string [, $s_mode = "Title" [, $i_instance = 1]] )




参数

$s_string 要搜索的字符串 (对于"embedded"或者"dialogbox",使用标题子字符串或者窗口句柄(HWND))
$s_mode [可选参数]: 指定搜索模式
Title = (默认) 主文档标题的子字符串
WindowTitle = 完整窗口标题的子字符串(替代文档标题)
URL = 当前网页的url或者url子字符串
Text = 当前网页body标记内的文本或者文本子字符串
HTML = 当前网页body标签内的HTML代码或者HTML代码子字符串
HWND = 浏览器窗口句柄
Embedded = 嵌入了控件的窗口的句柄或者标题子字符串
DialogBox = 模态/非模态的对话框的句柄或者标题子字符串
Instance = 忽略 $s_string, 从所有可用的浏览器实例中返回一个浏览器引用(通过匹配实例号)
$i_instance [可选参数]: 按照 $s_string 和 $s_mode 匹配的浏览器组/嵌入式浏览器组返回一个基于1开始的索引数组. 参考备注.



返回值

成功: 返回一个指向 InternetExplorer 对象的对象变量,嵌入式浏览器与对话框模块将返回一个窗口对象
失败: 返回 0 并设置 @ERROR
@Error 0 ($_IEStatus_Success) = 没有错误
5 ($_IEStatus_InvalidValue) = 无效值
7 ($_IEStatus_NoMatch) = 没有匹配项目
@Extended 包含无效参数的数量



注意/说明

_IEAttach provides the "dialogbox" parameter to attach to modal and modeless dialogs created by the browser. It is important to note that not all dialogs created through browser interaction can be attached to and controlled in this way. Many of these dialogs are actually standard windows and can be controlled through the traditional AutoIt window functions. A reliable way to tell the difference between these types of windows is to use the "AutoIt Window Info" tool to examine it -- if the window contains a control called "Internet Explorer_Server" then you can attach to it with this function, if it does not it is a standard window and traditional AutoIt windows functions must be used to control it.

HyperTextApplication (.hta) windows 也许可以用"embedded"选项来附加.

在 "dialogbox" 和 "embedded" 模式中可以用标准的Win*系列函数的高级窗口标题选择语法来代替标题子字符串搜索.

Use of "$i_instance" with the "embedded" mode: used to return a reference to a specific instance of a WebBrowser and is particularly useful when more than one exists in a particular window. If you pass a window title in $s_string using embedded mode, only the first window matching that title will be used. If the WebBrowser control you desire is in another window you must pass the HWnd of that window rather than the title, or use the advanced Window Title selection syntax available to the standard Win* functions.

Use of "$i_instance" with all modes other than "embedded": used to return a browser reference from a groups of all windows that match the criteria from $s_string and $s_mode. Instance order for DialogBox mode determined by the order returned by WinList() matching the title. For all other modes the Instance order is determined by the Shell.Windows collection.

"$i_instance" values > 1 are set to 1 and a warning message is displayed when used with "hwnd" mode or with "DialogBox" mode when an HWnd is passed in $s_string.

DialogBox and Embedded modes can be used to attach to standard browser windows, but the object returned is that if the top level Window in the browser and not the InternetExplorer object. Window objects do not offer access to all of the attributes of the InternetExplorer object (e.g. status text, address bar etc.). As well, if you attempt to use a function like _IENavigate on such an object you may receive COM errors due to the way that IE7 has implemented Tabs. It may be useful to find browser instances in this way, but it is recommended that you immediately use _IEAttach using one of the other modes and using information that you may have obtained from the Window object in order to get a reference to the associated InternetExplorer object.




相关

_IECreate, _IECreateEmbedded, _IEQuit


示例/演示


; *******************************************************
; Example 1 - Attach to a browser with "AutoIt" in its title, display the URL
; *******************************************************
;
#include <IE.au3>
$oIE = _IEAttach ("AutoIt")
MsgBox(0, "The URL", _IEPropertyGet ($oIE, "locationurl"))

; *******************************************************
; Example 2 - Attach to a browser with "The quick brown fox"
;               in the text of it's top-level document
; *******************************************************
;
#include <IE.au3>
$oIE = _IEAttach ("The quick brown fox", "text")

; *******************************************************
; Example 3 - Attach to a browser control embedded in another window
; *******************************************************
;
#include <IE.au3>
$oIE = _IEAttach ("A Window Title", "embedded")

; *******************************************************
; Example 4 - Attach to the 3rd browser control embedded in another window
;               Use the advanced window title syntax to use the 2nd window
;               with the string 'ICQ' in the title
; *******************************************************
;
#include <IE.au3>
$oIE = _IEAttach ("[REGEXPTITLE:ICQ; INSTANCE:2]", "embedded", 3)

; *******************************************************
; Example 5 - Create an array of object references to all current browser instances
;               The first array element will contain the number of instances found
; *******************************************************
;
#include <IE.au3>

Dim $aIE[1]
$aIE[0] = 0

$i = 1
While 1
    $oIE = _IEAttach ("", "instance", $i)
    If @error = $_IEStatus_NoMatch Then ExitLoop
    ReDim $aIE[$i + 1]
    $aIE[$i] = $oIE
    $aIE[0] = $i
    $i += 1
WEnd

MsgBox(0, "Browsers Found", "Number of browser instances in the array: " & $aIE[0])
 楼主| 发表于 2011-11-1 16:14:13 | 显示全部楼层
回复 4# 骗子

非常感谢你的帮助。
但这个方法还是不能解决问题
因为我并不知道这个窗口的url,也就是说,在autoit的脚本运行前,这个窗口已经打开了,至于它的url,是不定的。确定的只是每个url打开的页面都是这个样子的。

我现在用坐标点击的方式绕过去了这个问题,但由于每台电脑的这个字段所在的坐标都是不一样的,所以该问题还是没能解决,进一步期待着你们的帮助。

附绕过去的脚本:
WinWaitActive("Certificate Error: Navigation Blocked - Windows Internet Explorer")
MouseClick("left", 238, 391, 1)
 楼主| 发表于 2011-11-1 16:28:03 | 显示全部楼层
回复 5# 骗子

用_IEAttach的话,应该是可以实现我想要的的,但不知道这段脚本应该怎么去改:
#include <IE.au3>
WinWaitActive("Certificate Error: Navigation Blocked - Windows Internet Explorer")
$oIE = _IEAttach ("Certificate Error: Navigation Blocked - Windows Internet Explorer")
_IELoadWait ($oIE)
_IELinkClickByText ($oIE,"Continue to this website (not recommended).")

现在运行时,没有去点击那个link
具体抛出的信息如下:
>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "D:\My Documents\桌面\testhttps2.au3"   
--> IE.au3 V2.4-0 Warning from function _IEAttach, $_IEStatus_NoMatch
--> IE.au3 V2.4-0 Error from function _IELoadWait, $_IEStatus_InvalidDataType
--> IE.au3 V2.4-0 Error from function _IELinkClickByText, $_IEStatus_InvalidDataType
>Exit code: 0    Time: 2.221
发表于 2011-11-2 08:58:30 | 显示全部楼层
试试
$oIE = _IEAttach ("Certificate Error: Navigation Blocked - Windows Internet Explorer","WindowTitle")
或者
$oIE = _IEAttach ("Certificate Error: Navigation Blocked","Title")
===========================================
实在不行想办法修改下IE的安全设置,这个好像是IE的一个安全警告,应该在设置中能更改
 楼主| 发表于 2011-11-2 09:52:44 | 显示全部楼层
回复 8# 骗子

非常感谢你的热心帮助,你提供的这个两个方法都是可行的,谢谢谢谢
发表于 2011-11-2 10:55:12 | 显示全部楼层
哈哈,你也用火狐
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-6 03:10 , Processed in 0.085576 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表