【问题标题】:How to get elements using CSS Selector `contains` in selenium webdriver [duplicate]如何在selenium webdriver中使用CSS选择器`contains`获取元素[重复]
【发布时间】:2018-03-06 10:44:15
【问题描述】:

我曾尝试在 selenium webdriver 中使用带有 contains() 的 CSS 选择器,但我面对的是 NullPointerException

有人可以帮忙吗?

private static final String testcode = "p:contains('Notes')";

public String getTextCode(String codes) throws Exception {
    String jc = driver.findElement(By.cssSelector(codes)).getText();
    return jc;
}

【问题讨论】:

  • contains() 似乎是一个 JQuery 函数。请看这个类似的问题:stackoverflow.com/questions/5441680/…
  • W3C css 定位器不支持 contains(),selenium 使用 W3C 描述的浏览器支持的原生 css lcoator。你提到的 contains() 应该得到 JQuery 的支持。

标签: java selenium selenium-webdriver


【解决方案1】:

根据specifications,不支持。您可以使用 XPath。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-08
    • 2023-03-24
    • 2015-10-15
    • 2019-06-03
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    相关资源
    最近更新 更多