zoukankan      html  css  js  c++  java
  • Selenium WebDriver-通过断言页面是否存在某些关键字来确定页面按照预期加载

    #encoding=utf-8
    import unittest
    import time
    import chardet
    from selenium import webdriver
     
    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_assertKeyWord(self):
            url = "http://www.baidu.com"
            # 访问百度首页
            self.driver.get(url)
            self.driver.find_element_by_id("kw").send_keys(u"光荣之路自动化测试")
            self.driver.find_element_by_id("su").click()
            time.sleep(4)
            # 通过断言页面是否存在某些关键字来确定页面按照预期加载
            assert u"首页--光荣之路" in self.driver.page_source, u"页面源码中不存在该关键字!"
    
    
    
        def tearDown(self):
            # 退出IE浏览器
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
  • 相关阅读:
    Python批量删除字符串中两个字符中间值
    2020年大三下学期第十周学习心得
    2020年大三下学期第九周学习心得
    2020.2.4
    2020.2.3
    2020.2.2
    2020.2.1
    签到六(开发)
    签到五(开发)
    签到四(开发)
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8709275.html
Copyright © 2011-2022 走看看