selenium3 + python - alert_is_present定位

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未弹出")


posted @ 2019-06-08 14:38  Test挖掘者  阅读(764)  评论(0编辑  收藏  举报