<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] 前言 獲取頁面title的方法可以直接用driver.title獲取到,然后也可以把獲取到的結果用做斷言。 本篇介紹另外一種方法去判斷頁面title是否與期望結果一樣。用到提到的expected_conditions模塊里的title_is和title_contains兩種方法。 <br /> ## 一、源碼分析 1. 首先看下源碼,如下 ``` class title\_is(object): ??? ''' An expectation for checking the title of a page. ??? title is the expected title, which must be an exact match ??? returns True if the title matches, false otherwise. ??? ''' def __init__(self, title): self.title = title def __call__(self, driver): return self.title == driver.title ``` 2. 注釋翻譯:檢查頁面的title與期望值是都完全一致,如果完全一致,返回True,否則返回Flase 3. title_is()這個是一個class類型,里面有兩個方法 4. __init__是初始化內容,參數是title,必填項 5. __call__是把實例變成一個對象,參數是driver,返回的是self.title == driver.title,布爾值 <br /> ## 二、判斷title:title\_is() 1. 首先導入expected_conditions模塊 2. 由于這個模塊名稱比較長,所以為了后續的調用方便,重新命名為EC了(有點像數據庫里面多表查詢時候重命名) 3. 打開博客首頁后判斷title,返回結果是True或False ![Snipaste_2020-08-21_11-00-36.png](https://i.loli.net/2020/08/21/e7gBJMRwV8qbGvx.png) <br /> ## 三、判斷title包含:title_contains 1. 這個類跟上面那個類差不多,只是這個是部分匹配(類似于xpath里面的contains語法) 2. 判斷title包含'梔楠'字符串 ![Snipaste_2020-08-21_11-18-53.png](https://i.loli.net/2020/08/21/KfBMsg3TaInZYzQ.png) <br /> ## 四、參考代碼 ``` # coding:utf-8 from selenium import webdriver from selenium.webdriver.support import expected_conditions as EC driver = webdriver.Chrome() driver.get("https://www.cnblogs.com/zjut-cheng/") # 判斷title完全等于 title = EC.title_is(u'梔楠 - 博客園') print(title(driver)) # 判斷title包含 title1 = EC.title_contains(u'梔楠') print(title1(driver)) # 另一種寫法 r1 = EC.title_is(u'梔楠 - 博客園')(driver) r2 = EC.title_contains(u'梔楠')(driver) print(r1) print(r2) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看