Selenium timing refresh web page implementation code
- 2021-01-19 22:20:01
- OfStack
code
The code is very simple, mainly in order to be familiar with the functions of the Selenium library, for the subsequent SMS bombing to do a cushion
from selenium import webdriver
import time
import random
url = raw_input('Input your website:').strip()
num = int(raw_input('How much times do you want:'),10)
options = webdriver.FirefoxOptions()
options.add_argument('--headless')
browser = webdriver.Firefox(firefox_options=options)
browser.get(url)
print 'Please wait...'
for i in range(num):
i += 1
print 'Refresh +%d' %i
time.sleep(random.randint(1,3))
browser.refresh()
browser.quit()
print 'Good Bye!'
Added: How to refresh the current page
Use the method that calls the refresh page in webdriver
# coding=utf-8
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(6)
driver.get("https://www.baidu.com")
time.sleep(2)
try:
driver.refresh() # The refresh method refresh
print ('test pass: refresh successful')
except Exception as e:
print ("Exception found", format(e))
driver.quit()