1.浏览器的前进与后退
1 # _*_ coding:utf-8 _*_ 2 # 导入webdriver包 3 from selenium import webdriver 4 from time import sleep 5 driver = webdriver.Firefox() 6 driver.get("https://www.baidu.com/") 7 sleep(5) 8 print("访问news页") 9 driver.get("http://news.baidu.com/") 10 sleep(5) 11 driver.back()#浏览器后退 12 sleep(5) 13 driver.forward()#浏览器前进 14 sleep(5) 15 driver.refresh()#浏览器刷新 16 sleep(5) 17 driver.quit()
2.浏览器窗口大小控制
1 #!/usr/bin/env python 2 # _*_ coding:utf-8 _*_ 3 # 导入webdriver包 4 from selenium import webdriver 5 from time import sleep 6 driver = webdriver.Firefox() 7 driver.get("https://www.baidu.com/") 8 sleep(5) 9 driver.set_window_size(800,600) #浏览器设置大小 10 sleep(5) 11 driver.maximize_window() #浏览器全屏 12 sleep(5) 13 driver.quit()