Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/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
我在使用SeleniumWebDriver检索所有列表项时遇到了一个问题_Selenium - Fatal编程技术网

我在使用SeleniumWebDriver检索所有列表项时遇到了一个问题

我在使用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类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">
<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;i
IList countryList=driver.FindElements(By.XPath(“/*[@id='ul-countries']/li”);
对于(int i=0;i