如何在 Python 中使用 Selenium 在瀏覽器中執行後退和重新整理操作?
我們可以在 Selenium 中的瀏覽器中執行後退和重新整理操作。
要執行瀏覽器中的後退操作,需要使用 back 方法。
要重新整理瀏覽器,需要使用 refresh 方法。
這兩種方法都可以用於測試瀏覽器導航和網頁的重新載入。
示例
程式碼實現
from selenium import webdriver
#browser exposes an executable file
#Through Selenium test we will invoke the executable file which will then #invoke actual browser
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
# to maximize the browser window
driver.maximize_window()
#get method to launch the URL
driver.get("https://tutorialspoint.tw/index.htm")
# to print the page title in console
print(driver.title)
# to print the current URL in console
print(driver.current_url)
#get method to launch another URL
driver.get("https://tutorialspoint.tw/questions/index.php")
# to go back to the previous URL
driver.back()
#to refresh the browser
driver.refresh()
#to close the browser
driver.close()
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式語言
C++
C#
MongoDB
MySQL
Javascript
PHP