使用Selenium的程序
from selenium import webdriver
browser = webdriver.Firefox()
url = 'any_url'
browser.get(url)
browser.find_element_by_id('empty_cart_btn').click()
创建以下对话框:
Selenium中的代码是什么自动按OK?
试试accept()
的selenium.webdriver.common.alert
未经测试的代码如下:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
browser = webdriver.Firefox()
url = 'any_url'
browser.get(url)
browser.find_element_by_id('empty_cart_btn').click()
try:
WebDriverWait(browser, 5).until(EC.alert_is_present(), 'Waiting for alert timed out')
alert = browser.switch_to_alert()
alert.accept()
print "alert accepted"
except TimeoutException:
print "no alert"