python+selenium小結4:頁面的前進後退

#!/usr/bin/env python 
# -*- coding:utf-8 -*-
from selenium import webdriver
import time

options = webdriver.ChromeOptions()
prefs = {
    'profile.default_content_setting_values':
        {
            'notifications': 2
        }
}
options.add_experimental_option('prefs', prefs)  # 關掉瀏覽器左上角的通知提示
options.add_argument("disable-infobars")  # 關閉'chrome正受到自動測試軟件的控制'提示
driver = webdriver.Chrome(chrome_options=options)
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("https://blog.csdn.net/jusulysunbeamy")
# 頁面的前進和後退
try:
    time.sleep(1)
    driver.find_element_by_xpath("//*[@id=\"asideProfile\"]/div[2]/dl[1]/dt/a").click()  # 點擊左邊菜單的原創
    time.sleep(5)  # 這個等待時間是方便查看效果用的
    driver.back()  # 後退到網址:https://blog.csdn.net/jusulysunbeamy
    time.sleep(5)
    driver.forward()  # 前進到原創頁面https://blog.csdn.net/jusulysunbeamy?t=1
    print("清除成功")
except Exception as e:
    print("前進後退出現問題了:" + format(e))
time.sleep(5)
driver.quit()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章