selenium webdriver方法qiut()close()区别
2017-06-12 11:36
357 查看
最近在研究chrome headless 版本号59+ 但是selenium的webdriver最新版本最高支持chrome58。
driver.close()调试过程出现bug:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: failed to close window in 20 seconds
(Session info: headless chrome=59.0.3071.86)
(Driver info: chromedriver=2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262),platform=Mac OS X 10.11.6 x86_64)
查询close和qiut 的区别:
This is a good question I have seen people use Close() when they shouldn't. I looked in the source code for the Selenium Client & WebDriver C# Bindings and found the following.
Close the browser window that the driver has focus of
Calls Dispose()
all browser windows and safely ends the session
The code below will dispose the driver object, ends the session and closes all browsers opened during a test whether the test fails or passes.
In summary ensure that Quit() or Dispose() is called before exiting the program, and don't use the Close() method unless you're sure of what you're doing.
Note
I found this question when try to figure out a related problem why my VM's were running out of harddrive space. Turns out an exception was causing Quit() or Dispose() to not be called every run which then caused the appData folder to fill the hard drive. So
we were using the Quit() method correctly but the code was unreachable. Summary make sure all code paths will clean up your unmanaged objects by using exception safe patterns or implement IDisposable
Also
In the case of RemoteDriver calling Quit() or Dispose() will also close the session on the Selenium Server. If the session isn't closed the log files for that session remain in memory.
driver.close()调试过程出现bug:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: failed to close window in 20 seconds
(Session info: headless chrome=59.0.3071.86)
(Driver info: chromedriver=2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262),platform=Mac OS X 10.11.6 x86_64)
查询close和qiut 的区别:
This is a good question I have seen people use Close() when they shouldn't. I looked in the source code for the Selenium Client & WebDriver C# Bindings and found the following.
webDriver.Close()-
Close the browser window that the driver has focus of
webDriver.Quit()-
Calls Dispose()
webDriver.Dispose()Closes
all browser windows and safely ends the session
The code below will dispose the driver object, ends the session and closes all browsers opened during a test whether the test fails or passes.
public IWebDriver Driver; [SetUp] public void SetupTest() { Driver = WebDriverFactory.GetDriver(); } [TearDown] public void TearDown() { if (Driver != null) Driver.Quit(); }
In summary ensure that Quit() or Dispose() is called before exiting the program, and don't use the Close() method unless you're sure of what you're doing.
Note
I found this question when try to figure out a related problem why my VM's were running out of harddrive space. Turns out an exception was causing Quit() or Dispose() to not be called every run which then caused the appData folder to fill the hard drive. So
we were using the Quit() method correctly but the code was unreachable. Summary make sure all code paths will clean up your unmanaged objects by using exception safe patterns or implement IDisposable
Also
In the case of RemoteDriver calling Quit() or Dispose() will also close the session on the Selenium Server. If the session isn't closed the log files for that session remain in memory.
相关文章推荐
- 【学习笔记】Selenium WebDriver的Actions类中的sendKeys方法和WebElement.sendKeys方法的区别
- Selenium不同浏览器WebDriver处理方法
- Selenium webdriver 新跳转页面上找对象解决方法
- Selenium2(WebDriver)总结(三)---元素定位方法
- selenium2/webdriver启动各种浏览器的方法
- Selenium webdriver在最开始打开的时候浏览器的地址栏会出现data的解决方法
- selenium Webdriver 封装方法
- TestNG+Selenium Webdriver 数据(Excel)驱动的方法
- [乐意黎原创] Selenium里WebDriver中窗口的close()与quit()
- selenium webdriver 你所不知道的quit 和close
- selenium(webdriver)--不同浏览器处理SSL Certificate Error的方法
- selenium webdriver学习(十六)----------用selenium webdriver实现selenium RC中的类似的方法
- 最简便安装python+selenium-webdriver环境方法
- selenium webdriver使用过程中出现Element is not currently visible and so may not be interacted with的处理方法
- watir-webdriver 区别于watir的一些方法记录
- WebDriver(Selenium2) 常见异常及处理方法
- Selenium + Webdriver 学习(四) 元素定位方法
- selenium+python的WebDriverWait使用方法
- selenium webdriver 元素定位方法