Close a newly opened tab or window in Selenium IDE

↘锁芯ラ 提交于 2021-02-19 03:28:13

问题


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:

  1. click on link that opens the new tab
  2. add command waitForPopUp
  3. set focus to new tab via command selectPopUp
  4. make your verifications or other commands regarding to your content in new tab
  5. use command close to close tab
  6. use command selectWindow to set focus to the old window

Screenshot of my Selenium IDE commands:

Selenium IDE switch tabs

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!