隐式等待是只要有一个元素在设置的时间内没有找到,就会报超时

隐式等待是一个全局的设置,只要放在找东西语句的前面,它后面的找东西的语句都会默认等待设置的时间(这里是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()

最新文章

  1. 自己对js对原型链的理解
  2. 使用Android Butterknife
  3. Array方法
  4. CSS3学习总结3-3D与动画
  5. 关于(object sender, EventArgs e)
  6. memcache 的内存管理介绍和 php实现memcache一致性哈希分布式算法
  7. Android开源项目汇总【转】
  8. Jenkins问题汇总
  9. DropzoneJS 使用指南
  10. Linux云自动化运维第五课
  11. Pandoc将markdown转换为word
  12. python正则表达式判断素数【厉害了】
  13. uWSGI+Django (中)
  14. Node.js(day2)
  15. wpf项目打开多个窗体在任务栏只有一个任务
  16. windows上使用mkdocs搭建静态博客
  17. Mysql 插入中文错误:Incorrect string value: '\xE7\xA8\x8B\xE5\xBA\x8F...' for column 'course' at row 1
  18. [HackerRank]Choosing White Balls
  19. SQL Server 2008中SQL之WaitFor
  20. ballerina 学习二十六 项目docker 部署&& 运行(二)

热门文章

  1. 《超实用的Node.js代码段》连载二:正确拼接Buffer
  2. JFinal视频教程-JFnal学院分享课
  3. python基础教程总结14——测试
  4. POJ 4020 NEERC John's inversion 贪心+归并求逆序对
  5. leetcode 179. Largest Number 、剑指offer33 把数组排成最小的数
  6. 万恶之源 Python
  7. linux - mysql 安装教程
  8. CVE-2011-0065
  9. java基础—super关键字
  10. ll1文法