TA的每日心情 | 开心 2016-10-31 11:34 |
---|
签到天数: 16 天 连续签到: 1 天 [LV.4]测试营长
|
#coding=utf-8
from selenium import webdriver
from time import sleep
def login():
driver.switch_to_frame("login_frame")
driver.find_element_by_id("u").clear()
driver.find_element_by_id("u").send_keys("username")
driver.find_element_by_id("p").clear()
driver.find_element_by_id("p").send_keys("password")
driver.find_element_by_id("login_button").click()
def logout():
driver.find_element_by_link_text("退出").click() #1
#driver.find_element_by_xpath("//*[@id='SetInfo']/div[1]/a[3]").click() #2
sleep(5)
driver.quit()
driver = webdriver.Firefox()
driver.get("http://mail.qq.com/")
login()
logout()
运行报错:
Traceback (most recent call last):
File "mailqq.py", line 23, in <module>
logout()
File "mailqq.py", line 15, in logout
driver.find_element_by_link_text("退出").click()
File "D:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriv
er\remote\webdriver.py", line 314, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "D:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriv
er\remote\webdriver.py", line 744, in find_element
{'using': by, 'value': value})['value']
File "D:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriv
er\remote\webdriver.py", line 231, in execute
response = self.command_executor.execute(driver_command, params)
File "D:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriv
er\remote\remote_connection.py", line 392, in execute
data = utils.dump_json(params)
File "D:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriv
er\remote\utils.py", line 32, in dump_json
return json.dumps(json_struct)
File "D:\Python27\lib\json\__init__.py", line 244, in dumps
return _default_encoder.encode(obj)
File "D:\Python27\lib\json\encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "D:\Python27\lib\json\encoder.py", line 270, in iterencode
return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xcd in position 0: invalid continuation byte
我用的是UE编写的代码,默认格式是DOS,还有系统默认的编码是ASCII,请大家看看什么原因?如何解决?
还有就是我用#2的代码,运行也报错,提示找不到元素,为什么会找不到呢?
谢谢!
|
|