当我尝试执行此循环时会发生此错误:
Robot robox = new Robot();
WebDriver driver = new FirefoxDriver();
//LINKS
String[] l = new String[3];
l[0] = "http://www.google.com";
l[1] = "http://www.wallmart.com";
l[2] = "http://www.google.com";
for(int i = 0; i < l.length; i++){
driver.get(l[i]);
driver.manage().window().maximize();;
robox.keyPress(KeyEvent.VK_ALT);
robox.keyPress(KeyEvent.VK_F4);
robox.keyRelease(KeyEvent.VK_ALT);
robox.keyRelease(KeyEvent.VK_F4);
}
我读过这可能会发生,因为我关闭浏览器,但不知道如何解决这个问题。
错误
Exception in thread "AWT-EventQueue-0"
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the
remote browser. It may have died.
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:15:02'
System info: host: 'My-PC', ip: '10.0.0.50', os.name: 'Windows 7', os.arch: 'x86',
os.version: '6.1', java.version: '1.7.0_45'
答案 0 :(得分:1)
请阅读您在人类语言中尝试做的事情:
1. Open new Firefox window
2. Type "www.google.com" into Firefox adress bar and press Enter
3. Close Firefox
4. Type "http://www.wallmart.com" into Firefox adress bar and press Enter
在第4步,你必须对自己说:“等等,什么?但我确实关闭了它!”这就是我觉得错误的意义所在。所以为了解决这个问题,我建议在循环结束时添加driver = new FirefoxDriver();
:
for(int i = 0; i < l.length; i++){
driver.get(l[i]);
driver.manage().window().maximize();;
robox.keyPress(KeyEvent.VK_ALT);
robox.keyPress(KeyEvent.VK_F4);
robox.keyRelease(KeyEvent.VK_ALT);
robox.keyRelease(KeyEvent.VK_F4);
driver = new FirefoxDriver();
}
无论如何,您是否知道关闭窗口时您也可以拨打driver.close();
,它会像使用机器人一样完全?