Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Selenium Learning: controlling browsers

Shulou Source: shulou.com Published: 2022-06-03 06:23:56 11月23日 Update

1 controls the size of the browser window

Driver.set_window_size (480480) Code: from selenium import webdriverfrom time import * driver = webdriver.Chrome () url = "http://www.baidu.com"driver.get(url)print(" sets the width and height of the browser") driver.set_window_size (480480) sleep (3) print ("set window maximization") driver.maximize_window () sleep (3) driver.quit ()

two。 Control browser backward, forward back 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% "% (url)) driver.back () sleep (3) print (" forword to% s "% (url2)) ) driver.forward () sleep (3) driver.quit ()

3. Simulate the refresh of the browser

Manually refresh the (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 ()

Tags: Browser browsing control maximum code size manual method page learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MariaDB Xiaomi Shulou Tech Info OPPO Reno