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
 

你可能感兴趣的:(selenium自动化)