4.2)控制浏览器
2022-08-27 本文已影响0人
Jeff_9021
二、控制浏览器
# -*- coding:utf-8 -*-
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://www.baidu.com/")
# 控制浏览器窗口大小
print("设置浏览器宽480、高800")
driver.set_window_size(480, 800)
print("设置浏览器全屏显示")
driver.maximize_window()
# 控制浏览器前进、后退
first_url ='https://www.baidu.com/'
print("now access %s" %(first_url))
driver.get(first_url)
second_url ='http://news.baidu.com/'
print("now access %s" %(second_url))
driver.get(second_url)
print("back to %s" %(first_url))
driver.back()
print("forward to %s" %(second_url))
driver.forward()
# 模拟浏览器刷新
driver.refresh()