from selenium import webdriver
import time
driver = webdriver.Chrome("<your path to chromedriver>")
driver.get("http://google.com")
# Creating a fake notification. Just ignore this.
driver.execute_script("window.alert('This is an alert');")
time.sleep(2)
# Now here's what you are looking for
alert = driver.switch_to_alert()
alert.dismiss()
是的,当然!我给你举了一个例子,我故意让谷歌创建一个假的浏览器通知(只是为了演示)。您只需检查
alert.dismiss()
行我们开始了:
相关问题 更多 >
编程相关推荐