1 Controlling the size of the browser window
Driver.set_window_size (480,480) code:
From selenium import webdriverfrom time Import *driver = Webdriver. Chrome () url = "http://www.baidu.com" driver.get (URL) print ("Set browser width and height") driver.set_window_size (480,480) sleep (3) Print ("Set window maximized") Driver.maximize_window () sleep (3) driver.quit ()
2. Control browser back, forward, and forward methods
From selenium import webdriverfrom 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. Simulate the refresh of the browser
Manual Refresh (F5) page: 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 ()
Selenium learning: Controlling the browser