使用 WAIN 检测新的浏览器窗口
有没有办法测试链接是否在新的浏览器窗口(或浏览器选项卡)中打开?
更新:
到目前为止,我使用了以下代码:
var newBrowserWindow = Browser.AttachTo<IE>(Find.ByTitle(browserTitle));
Assert.That(newBrowserWindow.hWnd, Is.Not.EqualTo(existingBrowserWindow.hWnd));
我使用现有的浏览器窗口打开页面并单击链接。但是,当链接在现有浏览器中打开一个新选项卡(IE 的默认行为为 targer=_blank)时,它具有相同的窗口句柄,因为它是相同的浏览器窗口。那么如何检测新标签呢?
is there a way to test wether a link was opened in a new browser-window (or browser-tab)?
Update:
So far I used the following code:
var newBrowserWindow = Browser.AttachTo<IE>(Find.ByTitle(browserTitle));
Assert.That(newBrowserWindow.hWnd, Is.Not.EqualTo(existingBrowserWindow.hWnd));
Where I used the existingBrowserWindow to open a page and to click on a link. But when the link opens a new tab in the existing browser (default behaviour for IE with targer=_blank) it has the same window-handle, since it's the same browser window. So how can I detect a new tab?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的一些代码会有所帮助...,
无论如何,当链接打开一个新的浏览器窗口时我所做的是
Browser.AttachTo
支持Find.ByUri()
,Find.ByTitle()
和Find.By("hwnd", windowHandle)
根据文档。我只测试了 Find.ByUri() 和 Find.ByTitle() 方法。如果你想检测你的操作是否打开了一个新窗口,你可以这样做
据我所知,WatiN 不支持新选项卡。但 Internet Explorer 的默认行为是在新窗口中打开新链接。
Some code of yours would help...,
Anyway, what I do when a link open a new browser window is
Browser.AttachTo
supportsFind.ByUri()
,Find.ByTitle()
andFind.By("hwnd", windowHandle)
according to documentation. I only testedFind.ByUri()
andFind.ByTitle()
methods.if you want to detect if you action has opened a new window you could do
As far as I know, there is no support in WatiN for new tab. But the default behavior of internet explorer is to open new links in new window.