问题
Using Selenium IDE with Windows7 and Firefox, an automatic click on a link may produce either a new tab or a new window.
close() closes the original window or tab, not the new one. Maybe if I had the ID of the newly created one I could select it and then close it but I don't know how to do this automatically. I've asked on the Selenium forum and read the questions here, but they focus on WebDriver, not the IDE. Any help would be appreciated!
Stig
回答1:
I had same problem and found a solution:
- click on link that opens the new tab
- add command
waitForPopUp
- set focus to new tab via command
selectPopUp
- make your verifications or other commands regarding to your content in new tab
- use command
close
to close tab - use command
selectWindow
to set focus to the old window
Screenshot of my Selenium IDE commands:
That works for me.
回答2:
Use selectWindow(windowID)
command to switch to new window in Se IDE. You can select new window by its windowID/name/title.
Hope this helps...
回答3:
Agreed with surya use selectWindow(windowID), you can get the window title by right click on the page check the option verifyTitle and in front of that you have your Title. Hope it helps out.
回答4:
selectWindow(windowID) has option to mention title of the webpage/window as a way to identify the target window.
syntax = selectWindow title=My Special Window
note: title = title of webpage that is visisble in webpage's title bar. Or right click on webpage and select menu "Page source". In source doc, select the text between ....
So if the title of webpage = My Special Window, you will see My Special Window.
Hope this will help.
Swasati Paul
回答5:
You could use the iterator to iterate amongst the windows, close the new window and come back to the originalWindow. And you can put this under the try
block because it will only iterate if a new window opens. Or else, it will continue executing normally in the current window.
try{
Set <Strings> ids = driver.getWindowHandles();
Iterator <String> it = ids.iterator();
String currentPage = it.next();
String newPage = it.next();
driver.switchTo().window(newPage);
driver.close(); //it will close the new window and automatically come back to the currentPage
}
finally
{
//continue with your script here
//this script will run regardless of the execution of the execution of the try block
}
来源:https://stackoverflow.com/questions/13973908/close-a-newly-opened-tab-or-window-in-selenium-ide