python錯誤:UnicodeDecodeError: 'utf8' codec can't decode byte 0xe6 in position 0: unexpected end of da

1、錯誤緣由瀏覽器

在學習selenium自動化測試框架的時候,進行模仿瀏覽器搜索功能,輸入英文是沒問題,可是輸入中文就報錯,報錯代碼框架

    def test_baidu_search(self):
        """
        這裏必定要test開頭,把測試邏輯代碼封裝到一個test開頭的方法裏。
        :return:
        """
        self.driver.find_element_by_id('kw').send_keys('時間')
        time.sleep(1)
        try:
            assert '時間' in self.driver.title
            print ('Test Pass.')
        except Exception as e:
            print ('Test Fail.', format(e))

報錯內容:UnicodeDecodeError: 'utf8' codec can't decode byte 0xe6 in position 0: unexpected end of data學習

2、解決辦法測試

在中文後加.decode("utf-8") 設置爲utf-8spa

 assert '時間'.decode("utf-8") in self.driver.title
相關文章
相關標籤/搜索