简体   繁体   English

如何查找复选框总数-Selenium WebDriver

[英]How to find Total Number of Checkboxs - Selenium WebDriver

Is there a way to count total number of checkbox present? 有没有一种方法可以计算复选框总数?

this is html source code generating by page.. 这是按页面生成的html源代码。

<tr> 
  <td>
    <span style="padding-left:15px;">
    <input id="ctl00_ContentPlaceHolder1_Control1_stCat_8" type="checkbox" name="ctl00$ContentPlaceHolder1$AddControl1$cat$lstCat$8"/>
    <label for="ctl00_ContentPlaceHolder1_AddControl1_lstCat_8">Item 1</label>
    </span>
 </td>
</tr>

<tr> 
  <td>
    <span style="padding-left:15px;">
    <input id="ctl00_ContentPlaceHolder1_Control1_stCat_9" type="checkbox" name="ctl00$ContentPlaceHolder1$AddControl1$cat$lstCat$8"/>
    <label for="ctl00_ContentPlaceHolder1_AddControl1_lstCat_9">Item 2</label>
    </span>
  </td>
</tr>

<tr> 
  <td>
    <span style="padding-left:15px;">
    <input id="ctl00_ContentPlaceHolder1_Control1_stCat_10" type="checkbox" name="ctl00$ContentPlaceHolder1$AddControl1$cat$lstCat$8"/>
    <label for="ctl00_ContentPlaceHolder1_AddControl1_lstCat_10">Item 3</label>
    </span>
  </td>
</tr>

在此处输入图片说明

This (or something similar to it) should work. 这(或类似的东西)应该起作用。

// WARNING: Untested code. Locator syntax may be
// slightly incorrect.
// Using C#, but other languages are similar.
// Assume driver is a valid IWebDriver instance.
ReadOnlyCollection<IWebElement> checkboxes = driver.FindElements(By.CssSelector("input[type='checkbox']"));
Console.WriteLine(checkboxes.Count);
    int countedCheckBoxes = driver.FindElements(By.CssSelector("input[type='checkbox']")).Count;
public int CountCheckBoxes(IWebDriver driver)
    {
        int countedCheckBoxes = driver.FindElements(By.XPath("//input[@type='checkbox']")).Count;
        return countedCheckBoxes;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Selenium Webdriver - Java 查找网页上的复选框总数? - How to find the total number of checkboxes present on web page using Selenium Webdriver - Java? 如何使用Selenium WebDriver和Autohotkey获取HTML中的元素总数? - How to get the total number of elements in a HTML with Selenium WebDriver and Autohotkey? 如何使用 selenium webdriver 计算 webtable 中的总行数和列数 - How to count total number of rows and columns in a webtable using the selenium webdriver 如何使用Selenium Webdriver Java查找表行号 - How to find the table row number using Selenium Webdriver Java 如何使用Selenium Webdriver和C#获取DIV标记内具有ID的表元素的总数 - How to get total number of table elements having ID inside a DIV tag using Selenium Webdriver and C# 使用Selenium WebDriver查找表行号 - Find a table row number using selenium webdriver 如何在Selenium WebDriver中找到项目? - How to find an item in Selenium WebDriver? 硒webdriver找不到正确数量的元素 - selenium webdriver does not find the correct number of elements 如何在python中使用selenium webdriver从网页中提取Total Confirmed的信息 - How to extract the information of Total Confirmed from webpage with selenium webdriver in python 使用C#的Selenium Webdriver:如何从网页上的URL数量中找到URL,然后单击它? - Selenium Webdriver using C#: How to find a URL from number of URL on a webpage and click on it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM