【pytest框架之web自动化测试】---弹框处理
页面操作过程中经常遇到弹框,弹框一般分为alert、window、div弹框
window弹框可以用switch_to_windows方法处理,div弹框与普通定位方式无异;
alert可以用类似方法处理

举个例子
https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable获取页面弹窗并点击确定

上代码
# -*- coding:utf-8 -*- # author:xjw # date=2021/3/1 from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.wait import WebDriverWait from time import sleep from selenium.webdriver import ActionChains from Testdev.pytest.setup_teardown.test_login import login class Testwindows(login): #继承login类 def test_windows(self): self.driver.switch_to_frame('iframeResult') self.driver.find_element_by_xpath('//*[@id="draggable"]') action=ActionChains(self.driver) drag=self.driver.find_element_by_id('draggable') drop=self.driver.find_element_by_id('droppable') action.drag_and_drop(drag,drop).perform() #sleep(5) WebDriverWait(self.driver, 10).until(expected_conditions.alert_is_present()) self.driver.switch_to.alert.accept() sleep(2)
浙公网安备 33010602011771号