首页 > 编程语言 > 详细

python+selenium2自动化------quit()和close()区别

时间:2020-07-24 00:48:13      阅读:114      评论:0      收藏:0      [点我收藏+]

区别:

driver.quit():关闭整个浏览器

driver.close():关闭当前所在的句柄窗口

示例代码:

from selenium import webdriver
from time import sleep

class Demo1():
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()

    def test_quit_close(self):
        self.driver.get(http://www.baidu.com)
        sleep(3)

        #获取当前窗口句柄
        current_handle = self.driver.current_window_handle
        print("current_handle:",current_handle)

        #跳转到新窗口
        el = self.driver.find_element_by_link_text(省批次线).click()
        sleep(2)

        #获取打开的所有窗口
        all_handle = self.driver.window_handles
        print(all_handle,all_handle)
        for handle in all_handle:
            if handle != current_handle:
                self.driver.switch_to.window(handle)

        sleep(3)
        self.driver.find_element_by_xpath(//*[@id="root"]/div/div[1]/div/div/div/div/div[2]/div[4]/div/ul/li[9]/a).click()

        sleep(2)
        self.driver.close()
        self.driver.quit()


if __name__ == __main__:
    Demo1().test_quit_close()

 

python+selenium2自动化------quit()和close()区别

原文:https://www.cnblogs.com/Xiaojiangzi/p/13369219.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!