首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用selenium检索所有列表项时,我面临一个问题

在使用selenium检索所有列表项时,我面临一个问题
EN

Stack Overflow用户
提问于 2016-03-04 12:39:30
回答 1查看 35关注 0票数 0

问题:在div类msb容器中有一个条目列表。.There是列表中的162个条目,.I希望单击列表.There中的第150项,这也是一个滚动条,通过该滚动条,我们可以切换到其他项目并选择它。

html的外观:

代码语言:javascript
复制
<div class="mCSB_container" style="position:relative; top:0;">
<ul id="ul-countries">
<li>
 <input id="country-3" type="checkbox" name="c:3">
<label for="country-3">Afghanistan</label>
</li>
<li>
<input id="country-6" type="checkbox" name="c:6">
<label for="country-6">Albania</label>
</li>
---other countries 
 </li>
</ul>
</div>

我的代码看起来如何:

代码语言:javascript
复制
IList<IWebElement> countryList = driver.FindElements(By.XPath("//*[@id='ul-countries']/li"));

    for (int i = 0; i <= countryList.Count; i++)
     {
          string temp = countryList.ElementAt(i).Text;
           if (countryList.ElementAt(i).Text == "Brazil")
           {
               //do something 
           }
     }

我得到了162个国家的正确计数,但我认为它们没有被正确地填充--当我试图从第15个国家检索文本时--它给了我一个空的结果-- .It只填充了那些列表项目的文本,当我检查元素时,可以在屏幕上看到这些列表项目,我可以通过html看到列表项目中所有所需的数据,而不是通过我的代码,.I试图让睡眠进入而不是运气。

请提供您的意见,以解决上述问题。最亲切的问候

EN

回答 1

Stack Overflow用户

发布于 2016-03-04 17:34:14

代码语言:javascript
复制
IList<IWebElement> countryList = driver.FindElements(By.XPath("//*[@id='ul-countries']/li"));

for (int i = 0; i <= countryList.Count; i++)
 {
      string temp = countryList.ElementAt(i).findElement(By.CSS("label")).getText();
       if (temp.equals("Brazil"))
       {
           //do something 
       }
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35796326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档