首先使用switch_to.alert()方法进行定位,然后可以使用下面的操作

text:返回alert、confirm、prompt中的文字信息;

accept():接受现有警告框;

dismiss():解散现有警告框;

send_keys():在警告框中输入文本(如果可以输入的话);

---------------------------------------------------------------------------------------

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep driver = webdriver.Firefox() # 指定和打开浏览器
driver.get('http://www.baidu.com') link = driver.find_element_by_link_text("设置")
ActionChains(driver).move_to_element(link).perform() #鼠标悬停在上面
sleep(5)
driver.find_element_by_class_name("setpref").click() #点击高级搜索 sleep(5)
driver.find_element_by_class_name('prefpanelgo').click() #点击保存 sleep(5)
print(driver.switch_to.alert.text) #获取打印警告框里面的内容 sleep(5)
driver.switch_to.alert.accept() #点击确定 sleep(5)
driver.close()

python+selenium下弹窗alter对象处理02的更多相关文章

  1. python+selenium下弹窗alter对象处理01

    alt.accept() :                            等同于单击“确认”或者“OK” alt.dismiss() :                            ...

  2. python selenium下拉框定位

    一.前言 总结一下python+selenium select下拉选择框定位处理的两种方式,以备后续使用时查询: 二.直接定位(XPath) 使用Firebug找到需要定位到的元素,直接右键复制XPa ...

  3. Python+Selenium学习--定位一组对象

    场景 从上一节的例子中可以看出,webdriver可以很方便的使用find_element方法来定位某个特定的对象,不过有时候我们却需要定位一组对象,这时候就需要使用find_elements方法. ...

  4. Python+selenium下拉菜单选项

    案例:在我要自学网登录页面选择要保留的时间 具体页面如图所示: 使用前端工具查看部分页面代码: <select class="loinp" name="Cookie ...

  5. python selenium 多个页面对象类使用同一个webdriver(即只打开一个浏览器窗口)

    1 class BasePage(): 2 """selenium基类""" 3 4 def __init__(self, driver=N ...

  6. python selenium 下拉框

    下拉框的处理如下代码: 定位select有很多种方式,这里介绍两种定位方式 1.二次定位 先定位到下拉框:self.dr.find_element_by_css_selector('#business ...

  7. python+selenium元素定位之XPath学习02

    XPath 语法 XPath 使用路径表达式来选取 XML 文档中的节点或节点集.节点是通过沿着路径 (path) 或者步 (steps) 来选取的. XML 实例文档 我们将在下面的例子中使用这个 ...

  8. python+selenium元素定位之CSS学习02

    参考文档:https://www.runoob.com/cssref/css-selectors.html CSS选择器用于选择你想要的元素的样式的模式. "CSS"列表示在CSS ...

  9. Python+selenium之弹窗

随机推荐

  1. python中split()及os.path模块的使用方法

    返回path规范化的绝对路径path=os.path.abspath('test.py')print(path)输出 D:\Caps\test.pypath=os.path.abspath('D:\\ ...

  2. 编译安装cmake

    安装cmake 1.为什么用cmake?    mysql部分版本安装前编译需要用软件cmake,而不是我们之前通常使用的make! 百度百科:CMake 可以编译源代码.制作程式库.产生适配器(wr ...

  3. JAVA笔记26-网络编程(不等于网站编程)

    一.网络基础(TCP/IP详解) 1.IP协议(Internet Protocol):网络层,支持网间数据报通信.无连接数据报传送,数据报路由选择和差错控制. IPv4 32位(4字节),IPv6 1 ...

  4. 解决sonar的ES无法启动问题

    单独启动SonarQube自带的ElasticSearch报错 错误1.8:++PrintGCDetails找不到主类等 解决方法: 打开sonar/elasticsearch/config文件夹 修 ...

  5. 【leetcode】1189. Maximum Number of Balloons

    题目如下: Given a string text, you want to use the characters of text to form as many instances of the w ...

  6. 【leetcode】Max Area of Island

    国庆中秋长假过完,又要开始上班啦.先刷个题目找找工作状态. Given a non-empty 2D array grid of 0's and 1's, an island is a group o ...

  7. linux 配置内网yum源

    一.yum服务器端配置1.安装FTP软件#yum install vsftpd #service vsftpd start#chkconfig --add vsftpd#chkconfig vsftp ...

  8. MongoDB接口类函数

    [接口类定义] [java] view plaincopy /** * 项目名:SpiderCrawler * 文件名:MongoDBDao.java * 描述:TODO(用一句话描述该文件做什么) ...

  9. 2019hdu多校 Minimal Power of Prime

    题目链接:Click here 题目大意:求一个数分解质因数后的最小幂指数 Solution: 首先,我们肯定是不能直接暴力求解的 我们先考虑筛出1e4范围以内的所有质数,把x所有这个范围内的质因子筛 ...

  10. sh_07_continue

    sh_07_continue i = 0 while i < 10: # continue 某一条件满足时,不执行后续重复的代码 # i == 3 if i == 3: # 注意:在循环中,如果 ...