zoukankan      html  css  js  c++  java
  • Selenium WebDriver- 隐式等待

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

    隐式等待是一个全局的设置,只要放在找东西语句的前面,它后面的找东西的语句都会默认等待设置的时间(这里是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()
  • 相关阅读:
    NOI-1.1-04输出保留3位小数的浮点数
    百练7619-合影效果-2015正式D题-简单排序&输出格式
    百练6376-二维数组右上左下遍历-2015正式C题
    C++ 开发环境配置
    go语言 http学习
    Git 命令及分支管理学习
    配置go语言编辑环境
    DNS的过程
    Split Array into Consecutive Subsequences
    组委会正在为美团点评CodeM大赛的决赛设计新赛制
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8709599.html
Copyright © 2011-2022 走看看