webdriver处理弹框报警

上一篇 / 下一篇  2015-12-01 20:25:07 / 个人分类:Python

       以下为python代码: 

        driver.get("http://127.0.0.1/index.htm")
       #下面一句执行后会弹出alert 或者confirm :
        driver.find_element_by_xpath("//input[@name='sends']").click()  
        使对象a指到该弹出框:
        a=driver.switch_to_alert()

        a.accept()   # 相当于点击确定,或者使用   driver.execute("acceptAlert")
        a.dismiss()  # 相当于点击取消,或者使用   driver.execute("dismissAlert")
        a.text           #获取弹出框里的文字  或者使用  driver.execute("getAlertText")["value"]

TAG:

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-28  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 30848
  • 日志数: 12
  • 建立时间: 2015-10-29
  • 更新时间: 2017-04-20

RSS订阅

Open Toolbar