selenium操作浏览器的前进和后退
生活随笔
收集整理的這篇文章主要介紹了
selenium操作浏览器的前进和后退
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前進關鍵字:driver.forward()
后退關鍵字:driver.back()
?
測試對象:1、https://www.baidu.com/
2、https://www.sogou.com/
實例代碼:
1 # 導入測試所需的庫或者模塊 2 from selenium import webdriver 3 import unittest 4 import time 5 6 class ApitestStudy(unittest.TestCase): 7 # 找到瀏覽器驅動并執行 8 def setUp(self): 9 self.driver = webdriver.Chrome(executable_path = "F:\Python\Scripts\chromedriver.exe") 10 # 執行測試用例 11 def test_ApitestStudy_Url(self): 12 firstrequesturl = "https://www.sogou.com/" 13 secondrequesturl = "https://www.baidu.com/" 14 # 首先訪問sogou首頁 15 self.driver.get(firstrequesturl) 16 # 然后在訪問Baidu首頁 17 self.driver.get(secondrequesturl) 18 # 后退至上次訪問的sogou首頁 19 time.sleep(2) 20 self.driver.back() 21 # 前進至訪問的baidu首頁 22 time.sleep(2) 23 self.driver.forward() 24 print("...執行成功...") 25 def tearDown(self): 26 # 退出瀏覽器 27 self.driver.quit() 28 if __name__ == "__main__": 29 unittest.main()執行結果:
以上就是操作瀏覽器的前進與后退的實例代碼,比較初級,適合我這樣的小白。后邊其他的一些操作將會持續更新。敬請期待!!!
?
轉載于:https://www.cnblogs.com/Zhan-W/p/10771416.html
總結
以上是生活随笔為你收集整理的selenium操作浏览器的前进和后退的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html 基本布局介绍
- 下一篇: 十六个 HTML,CSS,jQuery,