driver.quit()与driver.close()的不同:
driver.quit(): Quit this driver, closing every associated windows;
driver.close(): Close the current window, quiting the browser if it is the last window currently open.

翻译成中文:

driver.close()     --  关闭当前窗口,如果是当前打开的最后一个窗口,则退出浏览器

driver.quit()       --   退出驱动,关闭所有相关的窗口

代码附录:

from selenium import webdriver
from time import sleep driver = webdriver.Chrome()
driver.get('http://sahitest.com/demo/index.htm')
print(driver.current_window_handle) # 查看当前window handle driver.find_element_by_link_text('Window Open Test').click() # 打开新window1
driver.find_element_by_link_text('Window Open Test With Title').click() # 打开新window2
print(driver.window_handles) # 查看所有window handles driver.close()
print(driver.window_handles) # 查看现在的所有window handles,可看到只是关闭了最开始的一个window,其他两个window还在 driver.quit() # 看到所有window都被关闭

  

selenium中driver.close()和driver.quit()的不同点的更多相关文章

  1. selenium中三大窗口切换

    我们在做UI自动化时,不得不会遇到一些窗口跳转与弹框,在这种的时候如果不进行切换的话,继续执行脚本必然会报错,所以我们就需要用到切换窗口的方法. selenium中主要是三种窗口 Windows窗口 ...

  2. Selenium执行cdp命令,driver.execute_cdp_cmd用法

    Chrome自带的开发者工具DevTools功能非常强大.有时候我们在使用Selenium操作浏览器时需要通过调用一下DevTools的方法来完成一些设置,如模拟移动设备,弱网模拟等等. Seleni ...

  3. driver.close()和driver.quit()

    driver.close()关闭当前窗口 driver.quit()退出驱动关闭所有窗口 from selenium import webdriver from time import sleep d ...

  4. driver.get()和driver.navigate().to()到底有什么不同?-----Selenium快速入门(四)

    大家都知道,这两个方法都是跳转到指定的url地址,那么这两个方法有什么不同呢?遇到这种情况,第一反应就是查查官方的文档. 官方文档的说法是:Load a new web page in the cur ...

  5. python selenium中如何测试360等基于chrome内核的浏览器

    转自:https://blog.csdn.net/five3/article/details/50013159 直接上代码,注意是基于chrome内核的浏览器,基于ie的请替换其中的chrome方法为 ...

  6. selenium中的三种等待方式(显示等待WebDriverWait()、隐式等待implicitly()、强制等待sleep())---基于python

    我们在实际使用selenium或者appium时,等待下个等待定位的元素出现,特别是web端加载的过程,都需要用到等待,而等待方式的设置是保证脚本稳定有效运行的一个非常重要的手段,在selenium中 ...

  7. python selenium中iframe切换、window切换方法

    一.selenium中iframe切换方法: 方法一:switch_to.frame frame函数中提供了三种定位方法:by index, name, or webelement. driver.s ...

  8. selenium中的元素操作之三大切换(二)

    一.窗口切换 使用方法: 1.获取到打开的所有的窗口,句柄handles all_handles = driver.window_handles print(all_handles) 2.获取当前的窗 ...

  9. Selenium中使用Cookies绕过登录

    在使用selenium测试后台时常常每个流程都需要走登录流程,这样自然比较浪费时间.如果遇到登录需要输入验证码等情况,就可能出师未捷身先死. 在Web应用中,登录状态通常是通过Cookie中对应的se ...

随机推荐

  1. shell登陆加载的文件, 快捷命令, tee管道, nohup和&

    1. login shell和nologin shell的理解: 字面意思, 需要登陆的shell和不需要登陆的shell. 正确解释为: 加载用户环境配置的shell 和不加载用户环境配置的shel ...

  2. Paper | Non-local Neural Networks

    目录 1. 动机 2. 相关工作 3. Non-local神经网络 3.1 Formulation 3.2 具体实现形式 3.3 Non-local块 4. 视频分类模型 4.1 2D ConvNet ...

  3. IT兄弟连 Java语法教程 流程控制语句 循环结构语句4

    do-while循环 Java还有一种循环是do-while.与for.while这些在循环顶部判断条件表达式的语句不同,do-while是在循环底部进行条件表达式的检查.这意味着do-while循环 ...

  4. SpringBoot系列之profles配置多环境(篇二)

    SpringBoot系列之profles配置多环境(篇二) 继续上篇博客SpringBoot系列之profles配置多环境(篇一)之后,继续写一篇博客进行补充 写Spring项目时,在测试环境是一套数 ...

  5. PyCharm 2017: Remote debugging using remote interpreter doesn't work

    I set up a remote interpreter and verified that I can run a script using the remote interpreter. Con ...

  6. mysql 常用命令行总结

    登录 mysql -h -u root -p 回车后输入密码,即可登录 直接进入某个库 -D 库名 mysql -h -u root -D account -p 列举数据库.表 show databa ...

  7. C#数组2(多维数组)

    using System; namespace ConsoleApp3 { struct WuGong { public string Name; public int Attack; } class ...

  8. 关于ScriptManager.RegisterStartupScript 摘录

    //ScriptManager.RegisterStartupScript 方法 (Control, Type, String, String, Boolean) public static void ...

  9. Abp vNext框架 从空项目开始 使用ASP.NET Core Web Application-笔记

    参考 Abp vNext框架 从空项目开始 使用ASP.NET Core Web Application http://www.vnfan.com/helinbin/d/745b1e040c9b4f6 ...

  10. FCC---Animate Multiple Elements at Variable Rates---还可以改循环时间,达到不同律动频率的效果

    In the previous challenge, you changed the animation rates for two similarly animated elements by al ...