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