0

我正在用 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 中引发 self.failureException(msg) AssertionError: False is not true

我尝试了其他几种方法,例如简单地尝试断言 id * strong text *exists

我的预感是问题围绕着“id”

有什么想法吗?

4

1 回答 1

2

You try to use incorrect xpath and insert id instead of tag name. So correct version will be

self.assert_(sel.is_element_present("//*[@id='" + id + "' and contains(@class,'" + name + "')]"))
于 2012-04-25T10:33:59.973 回答