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 可以很方便的实现字符串 ...
随机推荐
- Codeforces631C【栈维护+瞎搞】
题意: 百度. 思路: 如果该查询的R比前面的所有都大,那么前面所有都失效. 那么我先预处理出这些有效的. 那最坏的情况不就是栈里面元素(R)很多 n,n-1,n-2,n-3,n-4而且都是相反排序的 ...
- HttpClient 应用案例揭破应用Discuss论坛登录
闲来无事,写了一个对discuss论坛登录的案例,初次上场按照以前的惯例没成功,见过抓包分析discuss论坛成功完成,废话不多说 直接上代码. 1:winform 做客户端,添加HttpClient ...
- Windows10家庭版升级至专业版
控制面板--系统里面修改产品密钥即可. 密钥:VK7JG-NPHTM-C97JM-9MPGT-3V66T.(先断网,不然会提示升级失败)
- WAMP3.1.10/Apache 设置站点根目录
网上的资料很多都不起作用了,都是说修改 WAMP\bin\apache\apache2.4.27\conf\httpd.conf 文件,但是修改了之后完全没有效果!! 最后,稀里糊涂的把 WAMP\b ...
- 转 event 'utl_file I/O':
The ASH report shows tables and data files with wait event 'utl_file I/O': CHANGES No changes. CAUSE ...
- Function.prototype.apply.call
我们先从一道简单的题目开始,前几天在git上看到的: 定义log方法,它可以代理console.log的方法.log(1,2,3) => 1 2 3 通常,你的答案会是这样的: functi ...
- 重置 linux系统后要配置的基本组件操作
1.安装jdk https://www.cnblogs.com/shihaiming/p/5809553.html 2.安装mysql 3.安装tomcat
- PHP正则表达式 - 附录(常用正则表达式)
常用正则表达式附录I 平时做网站经常要用正则表达式,下面是一些讲解和例子,仅供大家参考和修改使用: "^\d+$" //非负整数(正整数 + 0) "^[0-9]*[1- ...
- TestNG ABC
TestNG ABC 资源 官网 :http://testng.org/doc/index.html Maven示例 <dependency> <groupI ...
- swift 第三方库迁移错误解决“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choo
先看看错误提示 这里Alamofire库报错,原因打开工程会Xcode会提示你覆盖到最新的3.0版本.但是仍然有些框架会出现一些问题 解决办法: 选择Pods - ReactiveCocoa - Sw ...