How to close a tab and open a new tab using Selenium RC

蓝咒 提交于 2019-12-11 06:36:14

问题


I'm working on selenium RC java. In my test case, I have to close a tab and then open a new tab in the same test case. Can anyone please tell me how to do it?


回答1:


Have you tried using Selenium IDE to record these scenarios? That's what I would try first.

Alternatively, try firing a Ctrl+T event to open a new tab:

selenium.keyDownNative("17");
selenium.keyPressNative("84");
selenium.keyUpNative("17"); 

and Ctrl+W to close the tab:

selenium.keyDownNative("17");
selenium.keyPressNative("87");
selenium.keyUpNative("17"); 



回答2:


To open new tab:

Robot r = new Robot(); 
r.keyPress(KeyEvent.VK_CONTROL); 
r.keyPress(KeyEvent.VK_T); 
r.keyRelease(KeyEvent.VK_CONTROL); 
r.keyRelease(KeyEvent.VK_T);

And close the tab opened:

r.keyPress(KeyEvent.VK_CONTROL); 
r.keyPress(KeyEvent.VK_W); 
r.keyRelease(KeyEvent.VK_CONTROL); 
r.keyRelease(KeyEvent.VK_W);


来源:https://stackoverflow.com/questions/4780852/how-to-close-a-tab-and-open-a-new-tab-using-selenium-rc

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