zoukankan      html  css  js  c++  java
  • selenium-浏览器窗口最大化、刷新、前进、后退

    实际测试过程中经常遇到打开一个页面并不是全屏显示,但是却希望它能够全屏显示或者新增一条记录后需要刷新一下看能不能再列表中正常显示。

    窗口最大化关键字:maximize_window()

    当前窗口进行刷新:refresh()

    #获取浏览器驱动
    dr=webdriver.Chrome()
    #添加隐式等待
    self.dr.implicitly_wait(5)
    #打开登录页面
    dr.get("https://www.basejy.com/#/")
    #窗口最大化
    dr.maximize_window()
    sleep(3)
    #刷新当前页面
    dr.refresh()

    前进关键字:driver.forward()

    后退关键字:driver.back()

    测试对象:1、https://www.baidu.com/

         2、https://www.sogou.com/

    # 导入测试所需的库或者模块
    from selenium import webdriver
    import unittest
    import time
    
    class ApitestStudy(unittest.TestCase):
        # 找到浏览器驱动并执行
        def setUp(self):
            self.driver = webdriver.Chrome# 执行测试用例
        def test_ApitestStudy_Url(self):
            firstrequesturl = "https://www.sogou.com/"
            secondrequesturl = "https://www.baidu.com/"
            # 首先访问sogou首页
            self.driver.get(firstrequesturl)
            # 然后在访问Baidu首页
            self.driver.get(secondrequesturl)
            # 后退至上次访问的sogou首页
            time.sleep(2)
            self.driver.back()
            # 前进至访问的baidu首页
            time.sleep(2)
            self.driver.forward()
            print("...执行成功...")
        def tearDown(self):
            # 退出浏览器
            self.driver.quit()
    if __name__ == "__main__":
        unittest.main()
  • 相关阅读:
    Spring Boot:自动配置原理
    centos7安装zookeeper
    spring集成RabbitMQ
    centos7安装RabbitMQ
    centos7安装MongoDB4.0(yum安装)
    nginx日志分割
    centos7 yum安装nginx
    centos7使用cronolog分割tomcat8.5的catalina.out日志
    ubuntu18安装微信
    idea打开dashboard
  • 原文地址:https://www.cnblogs.com/dingxinwen/p/13141514.html
Copyright © 2011-2022 走看看