一、简介
本文只针对用显示等待去判断window、iframe、alert是否存在,其中
window用的是new_window_is_opene()这个类,真判断是否存在,不切换
iframe用的是frame_to_be_available_and_switch_to_it()这个类,判断是否存在,存在返回True并切换
alert用的是alert_is_present()这个类,判断是否存在,存在返回True并切换,反之返回False
二、显示等待及判断导包
from selenium.webdriver.support.wait import WebDriverWait # 导入显示等待模块
from selenium.webdriver.support import expected_conditions as ec # 导入显示等待中判断的条件
三、window切换
用法
其中current_handles参数为在窗口变化之前的所有窗口总数
WebDriverWait(driver,10).until(ec.new_window_is_opened(current_handles))
**先来看下源码** class new_window_is_opened(object): """ An expectation that a new window will be opened and have the number of windows handles increase""" def __init__(self, current_handles): self.current_handles = current_handles def __call__(self, driver): return len(driver