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);