如何在 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.com/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.com/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