首页 > 编程语言 > 详细

selenium3 + python - alert_is_present定位

时间:2019-06-08 15:02:00      阅读:663      评论:0      收藏:0      [点我收藏+]
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
import time

driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
mouse = WebDriverWait(driver,10).until(lambda x:x.find_element("link text","设置"))
ActionChains(driver).move_to_element(mouse).perform()
WebDriverWait(driver,10).until(lambda x:x.find_element("link text","搜索设置")).click()
#选择设置项
s = WebDriverWait(driver,10).until(lambda x:x.find_element("id","nr"))
Select(s).select_by_visible_text("每页显示50条")
# 点保存按钮
js = "document.getElementsByClassName(‘prefpanelgo‘)[0].click();"
driver.execute_script(js)
# 判断弹窗结果
result = EC.alert_is_present()(driver)
if result:
print(result.text)
result.accept()
else:
print("alert未弹出")


selenium3 + python - alert_is_present定位

原文:https://www.cnblogs.com/Teachertao/p/10990653.html

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