Selenium WebDriver- 隐式等待
2024-10-12 19:11:13
隐式等待是只要有一个元素在设置的时间内没有找到,就会报超时
隐式等待是一个全局的设置,只要放在找东西语句的前面,它后面的找东西的语句都会默认等待设置的时间(这里是10秒),这是死等,除非立刻找到了,5秒找到了也是会等10秒。
隐式等待比较耗时,不推荐使用。
#encoding=utf-8
import unittest
import time
from selenium import webdriver
from selenium.webdriver import ActionChains class VisitSogouByIE(unittest.TestCase): def setUp(self):
#启动IE浏览器
#self.driver = webdriver.Firefox(executable_path = "e:\\geckodriver")
self.driver = webdriver.Ie(executable_path = "e:\\IEDriverServer") def test_implictWait(self):
# 导入异常类
from selenium.common.exceptions import NoSuchElementException, TimeoutException
# 导入堆栈类
import traceback
url = "http://www.sogou.com"
# 访问sogou首页
self.driver.get(url)
# 通过driver对象implicitly_wait()方法来设置隐式等待时间,最长等待10秒,如果10秒内返回则继续执行后续脚本
self.driver.implicitly_wait(10)
try:
# 查找sogou首页的搜索输入框页面元素
searchBox = self.driver.find_element_by_id("query")
# 在搜索输入框中输入“光荣之路自动化测试”
searchBox.send_keys(u"光荣之路自动化测试")
# 查找sogou首页搜索按钮页面元素
click = self.driver.find_element_by_id("stb")
# 点击搜索按钮
click.click()
except (NoSuchElementException, TimeoutException), e:
# 打印异常的堆栈信息
traceback.print_exc() def tearDown(self):
# 退出IE浏览器
self.driver.quit() if __name__ == '__main__':
unittest.main()
最新文章
- 自己对js对原型链的理解
- 使用Android Butterknife
- Array方法
- CSS3学习总结3-3D与动画
- 关于(object sender, EventArgs e)
- memcache 的内存管理介绍和 php实现memcache一致性哈希分布式算法
- Android开源项目汇总【转】
- Jenkins问题汇总
- DropzoneJS 使用指南
- Linux云自动化运维第五课
- Pandoc将markdown转换为word
- python正则表达式判断素数【厉害了】
- uWSGI+Django (中)
- Node.js(day2)
- wpf项目打开多个窗体在任务栏只有一个任务
- windows上使用mkdocs搭建静态博客
- Mysql 插入中文错误:Incorrect string value: '\xE7\xA8\x8B\xE5\xBA\x8F...' for column 'course' at row 1
- [HackerRank]Choosing White Balls
- SQL Server 2008中SQL之WaitFor
- ballerina 学习二十六 项目docker 部署&;&; 运行(二)