我正在使用具有 selenium 驱动程序的pyccuracy测试 Python 应用程序。
我的测试结果显示 xPaths 存在一些不稳定问题。有时我会收到无效 xPath 错误,但 xPath 有效。如果我再次运行测试,它可能会起作用。我已经按照堆栈跟踪,但我找不到解决方案。
堆栈跟踪:
I do not see "top-search-tag-name" element - FAILED - Error executing action <bound method ElementIsNotVisibleAction.execute of <pyccuracy.actions.core.element_actions.ElementIsNotVisibleAction object at 0x2283b10>> - Traceback (most recent call last):
File "/workspace/env_test/local/lib/python2.7/site-packages/pyccuracy/fixture_items.py", line 99, in execute
self.execute_function(context, *self.args, **self.kwargs)
File "/workspace/env_test/local/lib/python2.7/site-packages/pyccuracy/actions/core/element_actions.py", line 179, in execute
self.assert_element_is_not_visible(context, element_key, error_message)
File "/workspace/env_test/local/lib/python2.7/site-packages/pyccuracy/actions/__init__.py", line 147, in assert_element_is_not_visible
if self.is_element_visible(context, selector):
File "/workspace/env_test/local/lib/python2.7/site-packages/pyccuracy/actions/__init__.py", line 139, in is_element_visible
is_visible = context.browser_driver.is_element_visible(selector)
File "/workspace/env_test/local/lib/python2.7/site-packages/pyccuracy/drivers/core/selenium_driver.py", line 86, in is_element_visible
is_present = self.selenium.is_element_present(element_selector)
File "/workspace/env_test/local/lib/python2.7/site-packages/selenium/selenium.py", line 1369, in is_element_present
return self.get_boolean("isElementPresent", [locator,])
File "/workspace/env_test/local/lib/python2.7/site-packages/selenium/selenium.py", line 261, in get_boolean
boolstr = self.get_string(verb, args)
File "/workspace/env_test/local/lib/python2.7/site-packages/selenium/selenium.py", line 223, in get_string
result = self.do_command(verb, args)
File "/workspace/env_test/local/lib/python2.7/site-packages/selenium/selenium.py", line 217, in do_command
raise Exception, data
Exception: ERROR: Invalid xpath [2]: //form[@id='searchtop']//ul[@class = 'tags block editing']//li/a[@class = 'tag']
HTML 代码(已清理)
<form id="searchtop">
<ul class="tags block editing">
<li class="tag">
<a href="#" class="tag">Section Label</a>
<a href="#" class="remove" title="Remove filter"></a>
</li>
</ul>
...
</form>
在此测试中,我单击了删除过滤器链接,然后检查该元素是否不存在。xPath 是正确的。例如,在 Chrome 中,我在删除标记之前使用 $x(...) 选择了元素,并在删除它后得到一个空列表。这就是测试的作用。有时,相同的测试在完全相同的环境中运行而不会出错。
想法?