selenium控制窗口最大化、适合手机的宽度、适合pad的宽度等尝试下实例,网站是否做了响应式布局
#coding=utf-8 # 改变浏览器窗口大小、前进后退 from selenium import webdriver import time driver = webdriver.Firefox() driver.maximize_window() #浏览器最大化 driver.get("http://www.runoob.com/html/html-tutorial.html") time.sleep(2) driver.set_window_size(480,800) #改变窗口大小。这个网站做了响应式布局,分别看到三栏、两栏、一栏 time.sleep(2) driver.set_window_size(900,1000) time.sleep(2) driver.get("http://www.runoob.com") #访问第二个网页,练习前进后退 time.sleep(2) driver.back()#后退 print("back to url :"+driver.current_url) time.sleep(2) driver.forward() #前进 print("forward to url :"+driver.current_url) time.sleep(2) driver.quit()