from selenium import webdriver
d = webdriver.Firefox()
d.get('file://C:\我的代码\selenium自动化测试\alter.html')
d.find_element_by_id("alter").click()
#切到alter,返回一个alter对象:
alter = d.switch_to_alert()
print(type(alter))
#查看对话框文本信息:
print(alter.text)
#点击确认:
alter.accept()
#点击取消:
d.find_element_by_id("alter").click()
alter.dismiss()