1. 程式人生 > >assertTrue/False 判斷目標元素的內容與預期是否一致

assertTrue/False 判斷目標元素的內容與預期是否一致

sent method Corel rdo tca name 目標 rtt ret

from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
import unittest

class BlogHome(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        cls.driver = webdriver.Firefox()
        url = "https://www.cnblogs.com/EncoreLiu/"
cls.driver.get(url) cls.driver.implicitly_wait(30) @classmethod def tearDownClass(cls) -> None: cls.driver.quit() def test_01(self): ‘‘‘ 比較元素內容是否相等 :return: assertFalse 返回結果為 False ‘‘‘ locator = ("
id","blog_nav_sitehome") text = "博客1園" result = EC.text_to_be_present_in_element(locator,text)(self.driver) self.assertFalse(result) def test_02(self): ‘‘‘ 比較元素內容是否相等 :return: assertTrue 結果為true ‘‘‘ locator = ("id
","blog_nav_myhome") text = "首頁" result = EC.text_to_be_present_in_element(locator,text)(self.driver) self.assertTrue(result) if __name__ == __main__: unittest.main()

assertTrue/False 判斷目標元素的內容與預期是否一致