资源推荐:
视频资源: 软件测试相关系列视频
社区资源: 自动化测试交流群
今天在使用webdriver操作两个窗口时,其中父窗口为parent,子窗口为sub
1、使用driver.switchTo().window(sub);
2、然后关闭子窗口,调用driver.quit(),
3、driver.switchTo().window(parent);切换回到父窗口
4、driver.quit();关闭父窗口
程序执行到第四步时,出错了,提示类似“no a session ……”错误信息,查了一下api,才发现,quit()详细信息“Quits this driver, closing every associated window”,执行这个方法后,driver会关闭所有关联窗口
close()详细信息:Close the current window, quitting the browser if it's the last window currently open ,此方法是关闭当前窗口,或最后打开的窗口
弄明白了,这两个方法的不同,以上错误信息就能迎刃而解了