【发布时间】:2012-04-26 05:49:18
【问题描述】:
我正在使用 python 运行硒测试。我对以下 html 代码有一个特定的问题.....
<span class="cke_label" id="cke_8_label">Source</span>
我已经尝试了以下.......
self.assert_element_present_by_class('Source button', 'cke_8_label', 'cke_label')**
这里是函数............
def assert_element_present_by_class(self, description, id, name):
sel = self.selenium
try:
self.assert_(sel.is_element_present("//" + id + "[contains(@class,'" + name + "')]"))
logging.info('PASS: "' + description + '" is present')
except Exception:
logging.exception('FAIL: "' + description + '" is not present')
这给了我这个错误.......
文件“Template_Designer_P37.py”,第 293 行,在 assert_element_present_by_class self.assert_(sel.is_element_present("//" + id + "[contains(@class,'" + name + "')]")) 文件 “C:\Python27\lib\unittest\case.py”,第 420 行,在 assertTrue 中 raise self.failureException(msg) AssertionError: False is not true
我尝试了其他几种方法,例如简单地尝试断言 id *strong text*exists
我的直觉是问题围绕着“id”
有什么想法吗?
【问题讨论】:
-
试试这个:
self.assert_(self.sel.is_element_present("//*[@id='" + id + "' and contains(@class,'" + name + "')]"))