#前进
driver.forward()
#后退
driver.back()
from selenium import webdriver
import unittest
import time
class VisitSogouByIE(unittest.TestCase):
def setUp(self):
# 启动IE浏览器
self.driver = webdriver.Ie(executable_path = "g:\\IEDriverServer")
def test_visitRecentURL(self):
firstVisitURL = "http://www.sogou.com"
secondVisitURL = "http://www.baidu.com"
# 首先访问sogou首页
self.driver.get(firstVisitURL)
time.sleep(0.5)
# 然后访问baidu首页
self.driver.get(secondVisitURL)
# 返回上一次访问过的搜狗首页
time.sleep(0.5)
self.driver.back()
time.sleep(0.5)
# 再次回到百度首页
self.driver.forward()
def tearDown(self):
# 退出IE浏览器
self.driver.quit()
if __name__ == '__main__':
unittest.main()
使用Selenium进行网页导航

本文介绍了一种使用Selenium库在Python中自动化网页浏览的方法,包括如何通过IE浏览器访问不同的网站并使用forward和back方法在历史记录中前进和后退。
10万+

被折叠的 条评论
为什么被折叠?



