Python+Selenium自动化测试框架--控制浏览器(窗口大小、后退、前进)
一、控制浏览器的窗口:
# coding=utf-8 from selenium import webdriver import time driver = webdriver.Chrome() driver.implicitly_wait(5) driver.get("http:www.baidu.com") try: print("测试全屏模式") driver.maximize_window() time.sleep(3) print(driver.get_window_size()) print("测试最小化") driver.minimize_window() time.sleep(3) print(driver.get_window_size()) print("测试设置浏览器宽1024、高768显示") driver.set_window_size(1024, 768) time.sleep(3) print(driver.get_window_size()) except Exception as e: print("控制浏览器失败", format(e)) driver.quit()
通过上述实例得知:
全屏模式:maximize_window() 、最小化模式:minimize_window() ,都不需要传参
窗口大小控制:set_window_size() ,参数数字为像素点
获取窗口像素:get_window_size()
二、浏览器的前进、后退
# coding=utf-8 from selenium import webdriver driver = webdriver.Chrome() driver.implicitly_wait(5) url1 = "http://www.baidu.com" url2 = "http://news.baidu.com/" driver.get(url1) print(f"现在访问的是:{url1}") driver.get(url2) print("现在访问的是:%s" % url2) driver.back() print(f"执行后退操作,URL:{url1}") driver.forward() print(f"执行前进操作,URL:{url2}") driver.quit()
通过上述实例得知:
前进:forward() 后退:back()
相关推荐
MaggieMiaoMiao 2020-07-17
wuxiaaa 2020-07-01
Henryztong 2020-06-14
maxelliot 2020-06-11
abdstime 2020-06-10
Dipa 2020-06-09
Noseparte 2020-06-07
jszy 2020-05-25
xiaoyezihanghui 2020-05-19
宿命java 2020-05-17
lucialee 2020-03-07
Dipa 2020-03-06
woxxoole 2020-02-23
lucialee 2020-01-12
goodby 2020-01-01
retacnyue 2019-12-26
jszy 2019-12-24
Henryztong 2019-12-21