首先将窗口句柄存储在变量中,然后再使用它返回窗口。
//Store the current window handleString currentWindowHandle = this.webDriver.getWindowHandle();//run your javascript and alert pre((JavascriptExecutor)this.webDriver).executescript("alert('Test')"); this.webDriver.switchTo().alert().accept();//Switch back to to the window using the handle saved earlierthis.webDriver.switchTo().window(currentWindowHandle);此外,您可以尝试在切换到窗口后最大化它,这也应该激活它。
this.webDriver.manage().window().maximize();



