I am using Watin 2.1 to try to test file download and file open functionality for a website.
This worked well in Internet Explorer 8, but since Internet Explorer 9 there is a yellow-white download bar at the bottom of the view instead of a popup dialog window.
I found this answer:
https://stackoverflow.com/a/8532222/246622, which solves that problem, as long as the browser tab that I am interested in is on top.
If there are other tabs that are on top, it cannot not find the download bar.
The problem here is that these tests will open other tabs on top of the tab with the download bar, before the download starts.
So, how do I access the correct tab, or how do I switch the top/visible tab in internet explorer, or how do I get those other pages to open in other windows instead of in tabs in the same window, or how do I close those other tabs from my test application?
Here is the relevant piece of code:
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));
I tried this:
var lowerWindow = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(aBrowserTab.Hwnd, 2/*GW_HWNDNEXT*/)); // This gets a next lower window.
I was then planning on identifying the correct tab using a regex with the title:
titleRegex.IsMatch(windowMain.ToplevelWindow.Title)
but this gets a lower window instead of a lower tab in the same window.