2012-04-25 66 views
0

我正在使用python运行硒测试。我有HTML代码以下位一个具体问题.....使用Selenium和Python检查ID

<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') 

这给了我这个错误.......

File "Template_Designer_P37.py", line 293, in assert_element_present_by_class self.assert_(sel.is_element_present("//" + id + "[contains(@class,'" + name + "')]")) File "C:\Python27\lib\unittest\case.py", line 420, in assertTrue raise self.failureException(msg) AssertionError: False is not true

我已经尝试了几个其他的方法,如简单地试图断言ID * 强大的文本 *存在

我的直觉是,这个问题围绕“身份证”

有什么想法?

+0

试试这个:'self.assert_(self.sel.is_element_present( “// * [@ ID ='” +编号+ “ '并包含(@class,'” +名+'')]“))' – 2013-11-07 23:21:45

回答

2

您尝试使用不正确的xpath并插入id而不是标签名称。所以,正确的版本将是

self.assert_(sel.is_element_present("//*[@id='" + id + "' and contains(@class,'" + name + "')]")) 
+0

我认为'self.sel'会完成任务。 – 2013-11-07 23:23:12