我在使用SeleniumWebDriver检索所有列表项时遇到了一个问题
问题:我在div类msb容器中有一个项目列表。 。列表中有162项。我想单击列表中的第150项。还有一个滚动条,我们可以通过它转到其他元素并选择它 html的外观:我在使用SeleniumWebDriver检索所有列表项时遇到了一个问题,selenium,Selenium,问题:我在div类msb容器中有一个项目列表。 。列表中有162项。我想单击列表中的第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"> &
<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
}
}
-
阿富汗
-
阿尔巴尼亚
---其他国家
我的代码是什么样子的:
<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
}
}
IList countryList=driver.FindElements(By.XPath(“//*[@id='ul-countries']/li”);
对于(int i=0;iIList countryList=driver.FindElements(By.XPath(“/*[@id='ul-countries']/li”);
对于(int i=0;i