UnicodeWarning
来源:互联网 发布:mips linux gnu gcc 编辑:程序博客网 时间:2024/06/07 01:12
环境:
使用python2.7
错误示范:
#encoding:UTF-8
from selenium import webdriver
import unittest
class Login(unittest.TestCase):
def setUp(self):
self.driver=webdriver.Chrome(executable_path='/Users/xxx/Downloads/chromedriver')
self.driver.implicitly_wait(3)
self.base_url = "https://www.baidu.com"
def test_jump_login(self):
driver=self.driver
driver.get(self.base_url + "/")
act_title=driver.title
expect_title="百度一下,你就知道"
self.assertTrue(act_title==expect_title,msg="jump incorrect")
def tearDown(self):
driver=self.driver
driver.quit()
if __name__=="__main__":
unittest.main()
错误提示:
UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
self.assertTrue(act_title==expect_title,msg="jump incorrect")
解决方案1:
expect_title="百度一下,你就知道"
改成:!!
expect_title=u"百度一下,你就知道"
解决方案2:
act_title=driver.title
改成:!!
act_title=driver.title.encode('utf-8')
python2的编码和解码是需要学习的基础
- UnicodeWarning
- 错误:UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode的解决方案
- poj 3176 Cow Bowling
- 智能指正和强弱指针的实现
- 返回顶部
- secureCRT 日志保存并记录每条记录的时间
- java面试题之JDK和JRE的区别是什么?
- UnicodeWarning
- 33 款主宰 2017 iOS 开发的开源库
- 38. Count and Say
- 离散数学 p313 所有顶点都是偶度数的连通图有欧拉回路 证明
- ie8及其以下版本兼容性问题之文本省略
- Django 自定义认证系统
- 64位win7使用debug的方法
- 智能充电桩——为电动汽车的最后一米铺路!
- [leetcode]41. First Missing Positive(Java)