【发布时间】:2012-11-15 14:04:58
【问题描述】:
我正在使用 Watin 2.1 来尝试测试网站的文件下载和文件打开功能。 这在 Internet Explorer 8 中运行良好,但从 Internet Explorer 9 开始,视图底部有一个黄白色的下载栏,而不是弹出对话框窗口。
我找到了这个答案: https://stackoverflow.com/a/8532222/246622,解决了这个问题,只要我感兴趣的浏览器选项卡在顶部。 如果顶部还有其他选项卡,则找不到下载栏。 这里的问题是,这些测试会在下载开始之前打开带有下载栏的选项卡顶部的其他选项卡。
那么,我如何访问正确的选项卡,或者如何在 Internet Explorer 中切换顶部/可见选项卡,或者如何让这些其他页面在其他窗口中打开,而不是在同一选项卡中打开窗口,或者如何从我的测试应用程序中关闭这些其他选项卡?
以下是相关代码:
Window windowMain = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(browser.hWnd, 5/*GW_CHILD*/)); // This gets the topmost browser tab.
System.Windows.Automation.TreeWalker trw = new System.Windows.Automation.TreeWalker(System.Windows.Automation.Condition.TrueCondition);
mainWindow = trw.GetParent(System.Windows.Automation.AutomationElement.FromHandle(browser.hWnd));
windowDialog = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(windowMain.Hwnd, 5));
我试过了:
var lowerWindow = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(aBrowserTab.Hwnd, 2/*GW_HWNDNEXT*/)); // This gets a next lower window.
然后我打算使用带有标题的正则表达式来识别正确的选项卡:
titleRegex.IsMatch(windowMain.ToplevelWindow.Title)
但这会得到一个较低的窗口,而不是同一窗口中的较低选项卡。
【问题讨论】:
标签: c# internet-explorer-9 watin ui-automation microsoft-ui-automation