【问题标题】:Selenium C# : How do I count elements whose href contains a certain substring?Selenium C#:如何计算 href 包含某个子字符串的元素?
【发布时间】:2015-04-14 15:30:50
【问题描述】:

我对 Selenium C# 相当陌生。我想计算其 href 包含特定子环(“/Dashboards/CustomDashboards”)的元素的数量(下图)。我尝试使用这个: driver.FindElements(By.CssSelector("a[href='/Dashboards/CustomDashboard']")).Count;

但它返回 1 而我正在寻找的数字是 25。我不能使用部分链接选择器,因为它不引用 href。帮助将不胜感激。谢谢 :)

【问题讨论】:

    标签: c# selenium selenium-webdriver


    【解决方案1】:

    Count 工作正常,因为您正在寻找 /Dashboards/CustomDashboard

    如果您想Count 所有包含 /Dashboards/CustomDashboard(即后面带有 ID)的元素,您想将搜索更改为:

    driver.FindElements(By.CssSelector("a[href*='/Dashboards/CustomDashboard']")).Count;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-16
      • 2012-05-15
      • 1970-01-01
      • 2016-09-20
      • 1970-01-01
      • 2017-02-25
      • 1970-01-01
      • 2012-04-27
      相关资源
      最近更新 更多