首页 > 其他 > 详细

自动化测试常用脚本-窗口切换

时间:2019-09-29 00:43:17      阅读:124      评论:0      收藏:0      [点我收藏+]
'''新开一个窗口'''
def open_new_window(self, url, t=4):
    """
    :param url: 要访问的地址
    :t: 等待时间
    :return:
    """
    bef_windows = self.dr.window_handles
    js = 'window.open("%s");' % url
    self.dr.execute_script(js)
    self.switch_to_new_window(bef_windows)  # 进入新打开的窗口
    self.dr.maximize_window()
    sleep(t)
'''切换到新窗口'''
def switch_to_new_window(self, new_wndow):
    """
    :param bef_wndows: 新窗口的句柄
    :return: 返回窗口句柄
    """
    # 判断新窗口打开
    WebDriverWait(self.dr, 15, 1).until(EC.new_window_is_opened(new_wndow))
    all_windows = self.dr.window_handles
    for handle in all_windows:
        if handle not in self.window_list:  # window_list 为新窗口打开之前已存在的窗口句柄列表
            self.window_list.append(handle)
            self.dr.switch_to.window(handle)
            sleep(2)
            return handle

自动化测试常用脚本-窗口切换

原文:https://www.cnblogs.com/chenri/p/11605562.html

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