簡體   English   中英

Selenium C#:我如何計算其href包含某個子字符串的元素?

[英]Selenium C# : How do I count elements whose href contains a certain substring?

我對Selenium C#相當新。 我想計算其href包含特定子環(“/ Dashboards / CustomDashboards”)的元素數量(下圖)。 我嘗試使用它: driver.FindElements(By.CssSelector("a[href='/Dashboards/CustomDashboard']")).Count;

但它返回1而我正在尋找的數字是25.我無法使用部分鏈接選擇器,因為它沒有引用href。 幫助將不勝感激。 謝謝 :) 在此輸入圖像描述

Count正常工作,因為您正在尋找/Dashboards/CustomDashboard

如果要Count 包含 /Dashboards/CustomDashboard所有元素(即后面帶有ID), /Dashboards/CustomDashboard將搜索更改為:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM