1控制浏览器窗口的大小
driver.set_window_size(480,480) 代码:
from selenium import webdriver from time import * driver = webdriver.Chrome() url = "http://www.baidu.com" driver.get(url) print("设置浏览器的宽和高") driver.set_window_size(480,480) sleep(3) print("设置窗口最大化") driver.maximize_window() sleep(3) driver.quit()
2.控制浏览器后退、前进back和forward方法
from selenium import webdriver from time import * driver = webdriver.Chrome() url = "http://www.baidu.com" print(‘new access %s‘ %(url)) driver.get(url) url2 = ‘http://news.baidui.com‘ print(‘new access %s‘ %(url2)) driver.get(url2) sleep(3) print("back to %s" %(url)) driver.back() sleep(3) print("forword to %s" %(url2)) driver.forward() sleep(3) driver.quit()
3.模拟浏览器的刷新
手动刷新(F5)页面:driver.refresh()
from selenium import webdriver
from time import *
driver = webdriver.Chrome()
url = "http://www.baidu.com"
print(‘new access %s‘ %(url))
driver.get(url)
sleep(3)
driver.refresh()
sleep(3)
driver.quit()
时间: 2024-10-26 06:54:44