如何单击<ul>列表的<li>元素下的<i>标记?

时间:2019-09-17 07:49:28

标签: 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(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>

1 个答案:

答案 0 :(得分:1)

使用此代码可以直接获取所需的i元素

IWebElement selectmember = Driver.FindElement.By.XPath(".//ul[what attributes it have place here]//li[order number]//i")

使用此代码获取i元素数组以迭代单击

IWebElement[] selectmembers = Driver.FindElements.By.XPath(".//ul[attributes]//li//i").ToArray();
foreach(IWebElement q in selectmembers)
q.Click();