Index: javascript/core/scripts/selenium-browserbot.js =================================================================== --- javascript/core/scripts/selenium-browserbot.js (revision 1729) +++ javascript/core/scripts/selenium-browserbot.js (working copy) @@ -288,7 +288,12 @@ BrowserBot.prototype.selectWindow = function(target) { if (target && target != "null") { - this._selectWindowByName(target); + try { + this._selectWindowByName(target); + } + catch (e) { + this._selectWindowByTitle(target); + } } else { this._selectTopWindow(); } @@ -308,6 +313,11 @@ this.isSubFrameSelected = false; } +BrowserBot.prototype._selectWindowByTitle = function(target) { + var windowName = this.getWindowNameByTitle(target); + this._selectWindowByName(windowName); +} + BrowserBot.prototype.selectFrame = function(target) { if (target == "relative=up") { this.currentWindow = this.getCurrentWindow().parent; @@ -789,6 +799,26 @@ return targetWindow; }; +/** + * Find a window name from the window title. + */ +BrowserBot.prototype.getWindowNameByTitle = function(windowTitle) { + LOG.debug("getWindowNameByTitle(" + windowTitle + ")"); + + // First look in the map of opened windows and iterate them + for (var windowName in this.openedWindows) { + var targetWindow = this.openedWindows[windowName]; + + // If the target window's title is our title + if (targetWindow.document.title == windowTitle + && !this._windowClosed(targetWindow)) { + return windowName; + } + } + + throw new SeleniumError("Window does not exist from title"); +}; + BrowserBot.prototype.getCurrentWindow = function(doNotModify) { var testWindow = this.currentWindow; if (!doNotModify) { Index: javascript/tests/TestSuite.html =================================================================== --- javascript/tests/TestSuite.html (revision 1729) +++ javascript/tests/TestSuite.html (working copy) @@ -82,6 +82,7 @@ TestClickJavascriptHref TestFramesClickJavascriptHref TestSelectWindow + TestSelectWindowTitle TestWaitInPopupWindow TestType Index: javascript/tests/TestSelectWindowTitle.html =================================================================== --- javascript/tests/TestSelectWindowTitle.html +++ javascript/tests/TestSelectWindowTitle.html @@ -0,0 +1,188 @@ + + + + + + Test SelectWindow by title + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Test selectWindow by title
+
open../tests/html/test_select_window.html 
clickpopupPage
waitForPopUpmyPopupWindow5000
selectWindowSelect Window Popup 
verifyLocation*/tests/html/test_select_window_popup.html 
verifyTitleSelect Window Popup 
verifyAllWindowNames*,* 
verifyAllWindowNamesregexp:myNewWindow 
close
selectWindownull 
verifyLocation*/tests/html/test_select_window.html 
clickpopupPage
waitForPopUpmyNewWindow5000
selectWindowmyNewWindow 
verifyLocation*/tests/html/test_select_window_popup.html 
close
selectWindownull 
+

Select an anonymous window (one that isn't assigned to a variable)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
clickpopupAnonymous
waitForPopUpanonymouspopup5000
selectWindowanonymouspopup 
verifyLocation*/tests/html/test_select_window_popup.html 
clickclosePage
selectWindownull 
+ +

Try onclick close handler

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
clickpopupAnonymous
waitForPopUpanonymouspopup5000
selectWindowanonymouspopup 
verifyLocation*/tests/html/test_select_window_popup.html 
clickclosePage2
+ +

Leave the test in a selected window - the next test should begin in the main window

+ + +