[英]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.