selenium java list_java – 使用Selenium Webdriver获取div中的项目列表

本文演示了如何使用Selenium WebDriver的Java实现来定位并操作HTML中class为'facetContainerDiv'的div内的所有复选框。通过XPath选择器获取div元素,并创建一个IList来存储所有复选框,然后通过索引逐个点击这些复选框。
摘要由CSDN通过智能技术生成

请遵循以下与您的案例完全匹配的代码.

>为div下的div创建一个web元素的接口,类为facetContainerDiv

即为

2.创建一个包含第二个div内所有元素的IList,即:

3.使用索引访问每个复选框

请在下面找到代码

using System;

using System.Collections.Generic;

using OpenQA.Selenium;

using OpenQA.Selenium.Firefox;

using OpenQA.Selenium.Support.UI;

namespace SeleniumTests

{

class ChechBoxClickWthIndex

{

static void Main(string[] args)

{

IWebDriver driver = new FirefoxDriver();

driver.Navigate().GoToUrl("file:///C:/Users/chery/Desktop/CheckBox.html");

// Create an interface WebElement of the div under div with **class as facetContainerDiv**

IWebElement WebElement = driver.FindElement(By.XPath("//div[@class='facetContainerDiv']/div"));

// Create an IList and intialize it with all the elements of div under div with **class as facetContainerDiv**

IList AllCheckBoxes = WebElement.FindElements(By.XPath("//label/input"));

int RowCount = AllCheckBoxes.Count;

for (int i = 0; i < RowCount; i++)

{

// Check the check boxes based on index

AllCheckBoxes[i].Click();

}

Console.WriteLine(RowCount);

Console.ReadLine();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值