【问题标题】:Checking IDs with Selenium & Python使用 Selenium 和 Python 检查 ID
【发布时间】: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 + "')]"))

标签: python selenium


【解决方案1】:

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

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

【讨论】:

  • 我认为self.sel 会完成这项任务。
猜你喜欢
  • 1970-01-01
  • 2013-09-30
  • 1970-01-01
  • 1970-01-01
  • 2021-09-14
  • 2021-07-05
  • 2014-10-21
  • 2017-08-10
  • 1970-01-01
相关资源
最近更新 更多