问题:在div类msb容器中有一个条目列表。.There是列表中的162个条目,.I希望单击列表.There中的第150项,这也是一个滚动条,通过该滚动条,我们可以切换到其他项目并选择它。
html的外观:
<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>我的代码看起来如何:
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试图让睡眠进入而不是运气。
请提供您的意见,以解决上述问题。最亲切的问候
发布于 2016-03-04 17:34:14
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
}
}https://stackoverflow.com/questions/35796326
复制相似问题