python-判断alter是否存在
from selenium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import firefox
from selenium.webdriver.common.keys import Keys
#firefoxdriverpath=os.path.abspath("/Applications/Firefox.app/Contents/MacOS/firefoxdriver")
#os.environ["webdriver.firefox.driver"]=firefoxdriverpath
#driver=webdriver.Firefox(firefoxdriverpath)
#driver=webdriver.Firefox()
driver=webdriver.Firefox()
driver.get("http://www.baidu.com")
#点击打开搜索设置
driver.find_element_by_css_selector("#u1 > a[name='tj_settingicon']").click()
driver.find_element_by_css_selector("a.setpref").click()
#点击保存设置
driver.implicitly_wait(10)
#driver.find_element_by_css_selector("div#gxszButton a.prefpanelgo[href='#']").click()
driver.find_element_by_link_text("保存设置").click()
time.sleep(2)
#driver.find_element_by_css_selector("div#gxszButton a.prefpanelgo[href='#']")
#获取网页上的警告信息
#alert=driver.switch_to_alert().text()
if EC.alert_is_present:
print("Alert exists")
alert=driver.switch_to_alert()
print (alert.text)
alert.accept()
print("Alert accepted")
else:
print("NO alert exists")
'''
try:
WebDriverWait(driver,10).until(EC.alert_is_present(),
'Timed out waiting for PA creation ' +
'confirmation popup to appear.')
print("0")
alert=driver.switch_to_alert().text()
print("1")
text=alert.text()
print(text)
except TimeoutException:
print("no alert")
#接收警告信息
#alert.accept()
#print("3")
#得到文本信息并打印
#alert=driver.switch_to_alert()
#print("5")
#取消对话框(如果有的话)
#alert=driver.switch_to_alert()
#alert.dismiss()
#输入值(如果有的话)
#alert=driver.switch_to_alert()
#alert.send_keys("xxx")
'''
driver.quit()
如果switch_to_alert不工作,最重要的问题就是,有1个以上的浏览器开启,导致alert抓取不到。并且在使用switch_to_alert的时候时间会比较长一些,需要等待一会儿才能完成accept等的工作。
原因是因为多个浏览器开启导致无法准确定位到哪个浏览器上,例如同时开启了两个firefox的浏览器,webdriver就无法定位到要测试的那个浏览器上,也就无法正常的获取到测试的那台浏览器上的alert窗口。
python-判断alter是否存在的更多相关文章
- python判断字符串
python判断字符串 s为字符串s.isalnum() 所有字符都是数字或者字母s.isalpha() 所有字符都是字母s.isdigit() 所有字符都是数字s.islower() 所有字符都是小 ...
- 【Python备忘】python判断文件和文件夹是否存在
python判断文件和文件夹是否存在 import os os.path.isfile('test.txt') #如果不存在就返回False os.path.exists(directory) #如果 ...
- python 判断连个 Path 是否是相同的文件夹
python 判断连个 Path 是否是相同的文件夹 import os os.path.normcase(p1) == os.path.normcase(p2) normcase() 在 windo ...
- Python判断列表是否已排序的各种方法及其性能分析
目录 Python判断列表是否已排序的各种方法及其性能分析 声明 一. 问题提出 二. 代码实现 2.1 guess 2.2 sorted 2.3 for-loop 2.4 all 2.5 numpy ...
- python 判断变量是否存在 防止报错
Python判断变量是否存在 方法一:使用try: ... except NameError: .... try: var except NameError: var_exists = False e ...
- python 判断是否为中文
python在执行代码过程是不知道这个字符是什么意思的.是否是中文,而是把所有代码翻译成二进制也就是000111这种形式,机器可以看懂的语言. 也就是在计算机中所有的字符都是有数字来表示的.汉字也是有 ...
- (转)python 判断数据类型
原文:https://blog.csdn.net/mydriverc2/article/details/78687269 Python 判断数据类型有type和isinstance 基本区别在于: t ...
- python判断字符串是否为空的方法s.strip()=='' if not s.strip():
python 判断字符串是否为空用什么方法? 复制代码 s=' ' if s.strip()=='': print 's is null' 或者 if not s.strip(): p ...
- python 判断字符串中是否只有中文字符
python 判断字符串中是否只有中文字符 学习了:https://segmentfault.com/q/1010000007898150 def is_all_zh(s): for c in s: ...
- Python判断字符串编码以及编码的转换
转自:http://www.cnblogs.com/zhanhg/p/4392089.html Python判断字符串编码以及编码的转换 判断字符串编码: 使用 chardet 可以很方便的实现字符串 ...
随机推荐
- codeforces358D Dima and Hares【dp】
从本质入手,这个东西影响取值的就是相邻两个哪个先取 设f[i][0/1]为前i个(i-1,i)中先取i/i-1的值(这里不算上i的贡献 转移就显然了,注意要先复制-inf #include<io ...
- uva12186 Another Crisis
题目大意: 世界危机发生了,工人们请求加薪.一个老板和n个员工组成树状结构,每个员工都有自己的唯一上司,Boss的编号为0,员工1~n,工人们打算签署一个志愿书给老板,但无法跨级,当一个中级员工(非是 ...
- vue、React Nactive的区别(转载)
Vue与React的对比 Vue.js与React.js从某些反面来说很相似,通过两个框架的学习,有时候对一些用法会有一点思考,为加深学习的思索,特翻阅了两个文档,从以下各方面进行了对比,加深了对这两 ...
- F.Cards with Numbers
链接:https://ac.nowcoder.com/acm/contest/908/F 题意: AFei has many cards. Each card has a number written ...
- UVa 11168(凸包、直线一般式)
要点 找凸包上的线很显然 但每条线所有点都求一遍显然不可行,优化方法是:所有点都在一侧所以可以使用直线一般式的距离公式\(\frac{|A* \sum{x}+B* \sum{y}+C*n|}{\sqr ...
- 关系型数据库---MySQL---数据库设计三大范式
1.第一范式: 1.1.1 数据表的每个数据列具有原子性: 1.1.2 同一个数据表中内容相似的数据列必须消除: 2.第二范式: 第一范式的基础上,每个数据表只描述一件事: 3.第三范式: 第二范式的 ...
- (转)nginx利用geo模块做限速白名单以及geo实现全局负载均衡的操作记录
nginx利用geo模块做限速白名单以及geo实现全局负载均衡的操作记录 原文:http://www.cnblogs.com/kevingrace/p/6165572.html Nginx的geo模块 ...
- rabbitmq 不发送ack消息如何处理:rabbitmq可靠发送的自动重试机制
转载地址:http://www.jianshu.com/p/6579e48d18ae http://www.jianshu.com/p/4112d78a8753 接这篇 在上文中,主要实现了可靠模式的 ...
- Redis的数据类型(lists、Sets)
lists类型 Redis 列表是简单的字符串列表,按照插入顺序排序.你可以添加一个元素到列表的头部(左边)或者尾部(右边) LPUSH 命令插入一个新的元素到头部, 而 RPUSH 插入一个新元素导 ...
- 30个提高Web程序执行效率的好经验
尽量避免使用DOM.当需要反复使用DOM时,先把对DOM的引用存到JavaScript本地变量里再使用.使用设置innerHTML的方法来替换document.createElement/append ...