2

我正在使用具有 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(...) 选择了元素,并在删除它后得到一个空列表。这就是测试的作用。有时,相同的测试在完全相同的环境中运行而不会出错。

想法?

4

1 回答 1

0

我在这里看到两个问题:

  1. 即使出现错误,您的测试似乎仍在继续运行
  2. 在执行下一个命令之前,您无需等待元素。

我没有看到“top-search-tag-name”元素 - 失败 - 错误执行

此错误意味着.. 元素“top-search-tag-name”不存在。通常发生在应用程序太慢或未完全加载时。要解决此问题,请尝试在继续之前等待元素

异常:错误:无效的xpath [2]://form[@id='searchtop']//ul[@class = 'tags block editing']//li/a[@class = 'tag']

xpath 似乎是有效的。您介意将 xpath 更改为更短并试一试吗? //form[@id='searchtop']//[a.='Section Label']

于 2014-02-03T19:06:35.033 回答