在WebDriver中处理JavaScript所生成的alert、confirm以及prompt,具体方法是使用switch_to_alert()方法定位到alert、confirm以及

prompt,然后使用text/accept/dismiss/send_keys等方法进行操作。

text:    返回 alert/confirm/prompt中的文字信息
accept(): 接受现有警告框
dismiss(): 解散现有警告框
send_keys(KeysToSend): 发送文本至警告框
KeysToSend: 将文本发送至警告框
 from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep def abcd():
# 打开浏览器
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
# 鼠标悬停到设置
obj = driver.find_element_by_link_text("设置")
ActionChains(driver).move_to_element(obj).perform()
# 点击搜索设置
driver.find_element_by_link_text("搜索设置").click()
# 点击保存设置
driver.find_element_by_class_name("prefpanelgo").click()
sleep(3)
# 接受警告框
driver.switch_to_alert().accept()

selenium webdriver——JavaScript警告窗处理的更多相关文章

  1. 转:selenium webdriver 执行javascript代码

    在用selenium webdriver 编写web页面的自动化测试代码时,可能需要执行一些javascript代码,selenium本身就支持执行js,我们在代码中import org.openqa ...

  2. selenium webdriver ——执行javascript代码

    在代码中import org.openqa.selenium.JavascriptExecutor;就可以使用executeScript.executeAsyncScript这两个方法了 execut ...

  3. selenium多表单切换以及多窗口切换、警告窗处理

    selenium表单切换 在做UI自动化,有时候要定位的元素属性在页面上明明是唯一的.却怎么也不执行对元素的操作动作,这时候多半是iframe表单在作怪. 切入表单:iddriver.switch_t ...

  4. selenium webdriver (python)的基本用法一

    阅在线 AIP 文档:http://selenium.googlecode.com/git/docs/api/py/index.html目录一.selenium+python 环境搭建........ ...

  5. 转载 基于Selenium WebDriver的Web应用自动化测试

    转载原地址:  https://www.ibm.com/developerworks/cn/web/1306_chenlei_webdriver/ 对于 Web 应用,软件测试人员在日常的测试工作中, ...

  6. selenium webdriver API

    元素定位 #coding=utf-8 from selenium import webdriver from selenium.webdriver.firefox.firefox_binary imp ...

  7. selenium webdriver (python)大全

    webdriver的简介 硒2.0的主要新功能是集成的webdriver的API.webdriver的设计除了解决一些seleniumr-RC API的一些限制,与webdriver 的整合,将提供一 ...

  8. Selenium WebDriver Api 知识梳理

    之前一直没有系统的梳理WebDriver Api的相关知识,今天借此机会整理一下. 1.页面元素定位 1.1.8种常用定位方法 # id定位 driver.find_element_by_id() # ...

  9. Python + Selenium WebDriver Api 知识回顾

    一直再用 Selenium WebDriver 但是用的都比较零散,也没有做过总结,今天借此机会,整理一下,方便大家使用时查阅 webDriver  的属性 ['CONTEXT_CHROME', 'C ...

随机推荐

  1. git常用命令图解

  2. 使用Mac的过程中的一些小操作

    前言:使用Mac的过程中的一些小操作 查看Mac系统是32位还是64位: 方法1: 点击左上角的苹果按钮->关于本机->概览->系统报告->软件->偏好设置面板:右侧有提 ...

  3. javaWeb css图文混排

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. input宽度超出

    设置样式:style=“width:100%”;即可

  5. Element-ui组件--pagination分页

    一般写后台系统都会有很多的列表,有列表就相应的要用到分页,根据项目中写的几个分页写一下我对分页的理解,就当是学习笔记了. 这是Element-ui提供的完整的例子 <template>  ...

  6. python中的文件操作小结1

    #!/usr/local/bin/python3 # -*- coding:utf-8 -*- f=open("test_1",'r',encoding="utf-8&q ...

  7. 裸机——DDR

    1.DDR介绍 DDR,是SDRAM的改进,是双通道的SDRAM, SDRAM是同步动态随机访问存储器. SDRAM与SRAM相对于,二者的特点是: SDRAM 需要初始化,使用时许访问,价格便宜. ...

  8. HDU 5446 Unknown Treasure (卢卡斯+CRT

    代码: #include"bits/stdc++.h" #define db double #define ll long long #define vec vector<l ...

  9. 011---Djang的cookie和session

    -------------------------------------------------------------cookie与session------------------------- ...

  10. keil调试问题记录

    1.错误类型:L6218E:Underfined symbol &&&&&&&&& (referred form &&a ...