if EC.alert_is_present: print("Alert exists") else: print("NO alert exists")什么情况下会走else语句,没有弹出alert为啥没走else

dingzhou_duyb 发布于 2016/02/03 10:57
阅读 428
收藏 0

from selenium import webdriver


import time

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver import firefox

from selenium.webdriver.common.keys import Keys






#firefoxdriverpath=os.path.abspath("/Applications/Firefox.app/Contents/MacOS/firefoxdriver")

#os.environ["webdriver.firefox.driver"]=firefoxdriverpath

#driver=webdriver.Firefox(firefoxdriverpath)

#driver=webdriver.Firefox()

driver=webdriver.Firefox()

driver.get("http://www.baidu.com")

#点击打开搜索设置

driver.find_element_by_css_selector("#u1 > a[name=‘tj_settingicon‘]").click()

driver.find_element_by_css_selector("a.setpref").click()

#点击保存设置

driver.implicitly_wait(10)

#driver.find_element_by_css_selector("div#gxszButton a.prefpanelgo[href=‘#‘]").click()

driver.find_element_by_link_text("保存设置").click()

time.sleep(2)

#driver.find_element_by_css_selector("div#gxszButton a.prefpanelgo[href=‘#‘]")

#获取网页上的警告信息

#alert=driver.switch_to_alert().text()

if EC.alert_is_present:

    print("Alert exists")

    alert=driver.switch_to_alert()

    print (alert.text)

    alert.accept()

    print("Alert accepted")

else:

    print("NO alert exists")

加载中
0
regend
regend
没有弹窗的时候就会走else
d
dingzhou_duyb
没有弹窗并没有走else
返回顶部
顶部