selenium自動化實踐Day4--斷言頁面標題

# coding=utf-8
import time
from selenium import webdriver


import selenium
chrome_driver="C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
driver=webdriver.Chrome(executable_path=chrome_driver)


driver.maximize_window()
driver.get('https://www.baidu.com')
time.sleep(1)
# 方法一
try:
    assert u"百度一下" in driver.title
    print('Assertion test pass.')
except Exception as e:
    print('Assertion test fail.', format(e))
# 方法二
if u"百度一下,你就知道" == driver.title:
    print('Assertion test pass.')
else:
    print('Assertion test fail.')

print(driver.title)

執行結果:

E:\python3.8.2\python.exe E:/PycharmProjects/selenium/testsuites/first.py
Assertion test pass.
Assertion test pass.
百度一下,你就知道

Process finished with exit code 0
 

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