【发布时间】:2015-01-20 17:25:17
【问题描述】:
我希望 selenium 为我目前保存到输出日志中的 selenium 测试提供更简单和直接的输出
======================================================================
ERROR: test3_AnswerTest (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test.py", line 98, in test3_FashionTest
driver.find_element_by_xpath("//a[contains(.,'Answer')]").click()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 230, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 662, in find_element
{'using': by, 'value': value})['value']
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: Error Message => 'Unable to find element with xpath '//a[contains(.,'Ass')]''
caused by Request => {"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"106","Content-Type":"application/json;charset=UTF-8","Host":"10.0.0.100:49044","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"xpath\", \"sessionId\": \"fd4e8db0-a0c6-11e4-9624-f33660aa508e\", \"value\": \"//a[contains(.,'Ass')]\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/fd4e8db0-a0c6-11e4-9624-f33660aa508e/element"}
Screenshot: available via screen
是否可以将此输出简化为类似的内容?
NoSuchElementException: Message: Error Message => 'Unable to find element with xpath '//a[contains(.,'Answer')]''
当前的错误信息是
Traceback (most recent call last):
NoSuchElementException: Message: Error Message => 'Unable to find element with xpath '//a[contains(.,'Answer')]''
caused by Request => {"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"106","Content-Type":"application/json;charset=UTF-8","Host":"10.0.0.100:49044","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"xpath\", \"sessionId\": \"12e538b0-a0e3-11e4-af45-ff6a851f3fb0\", \"value\": \"//a[contains(.,'Ass')]\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/12e538b0-a0e3-11e4-af45-ff6a851f3fb0/element"}
Screenshot: available via screen
【问题讨论】:
-
检查 python 回溯模块。 docs.python.org/2/library/traceback.html
标签: python selenium xpath exception-handling selenium-webdriver