Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何单击列表的元素下的标记?_C#_List_Selenium - Fatal编程技术网

C# 如何单击列表的元素下的标记?

C# 如何单击列表的元素下的标记?,c#,list,selenium,C#,List,Selenium,如何单击li标记下的I标记 li是此ul列表中显示的选项,i是我需要单击的每个li的复选框 我尝试的是: IList<IWebElement> dropDownMenu = driver.FindElements(By.CssSelector("div.col-lg-6:nth-child(1) > ul:nth-child(1)")); IList<IWebElement> selectmember = dropDownMenu[0].FindElements(B

如何单击li标记下的I标记

li是此ul列表中显示的选项,i是我需要单击的每个li的复选框

我尝试的是:

IList<IWebElement> dropDownMenu = driver.FindElements(By.CssSelector("div.col-lg-6:nth-child(1) > ul:nth-child(1)"));
IList<IWebElement> selectmember = dropDownMenu[0].FindElements(By.TagName("i"));
var count = selectmember.Count;
if (count > 0)
      {
       selectmember[0].Click();
      }
HTML代码:

<li ng-repeat="s in servicePlans | orderBy:'name' | filter:filterServicePlans" ng-if="!($index % 2)" style="font-size: 12px; margin: 3px 0; min-height: 24px; list-style-type: none;" class="crop-long-text ng-scope">
    <a href="javascript:;" style="text-decoration: none" class="font-dark" ng-click="clickService(s)">
         <i class="fa fa-minus-square-o" ng-class="{ 'fa-square-o': s.checked == false, 'fa-check-square-o': s.checked, 'fa-minus-square-o' : s.checked == null }" style="margin-right: 5px;"></i>
                                        <span class="ng-binding">To-Do (BPOS_S_TODO_1)</span>
    </a>
</li>

sGet直接到所需的i元素,您可以使用此代码

IWebElement selectmember = Driver.FindElement.By.XPath(".//ul[what attributes it have place here]//li[order number]//i")
IWebElement[] selectmembers = Driver.FindElements.By.XPath(".//ul[attributes]//li//i").ToArray();
foreach(IWebElement q in selectmembers)
q.Click();
获取要迭代的i元素数组,单击此代码即可

IWebElement selectmember = Driver.FindElement.By.XPath(".//ul[what attributes it have place here]//li[order number]//i")
IWebElement[] selectmembers = Driver.FindElements.By.XPath(".//ul[attributes]//li//i").ToArray();
foreach(IWebElement q in selectmembers)
q.Click();

这不是标准的C代码。。。我不知道这是什么,除非是一些自定义的C代码。此外,还有。在开始时,不需要XPath。仅当您希望从特定元素开始搜索时才使用,例如Driver.FindElementBy.IdmyId.FindElementBy.XPath//div;