列表视图内的Selinium-webdriver ul无法自动化

时间:2015-12-03 09:25:47

标签: selenium

<div id="from-list" class="k-list-container k-popup k-group k-reset k-state-border-up" data-role="popup" style="height: auto; display: block; font-size: 16px; font-family: "TR",arial; font-stretch: normal; font-style: normal; font-weight: 500; line-height: 23.2px; width: 206.6px; transform: translateY(0px); position: absolute;">
<ul id="from_listbox" class="k-list k-reset" unselectable="on" style="overflow: auto; height: auto;" tabindex="-1" role="listbox" aria-hidden="false" aria-live="polite">
<li class="k-item" unselectable="on" data-idx="0" role="option" tabindex="-1">pr.sud@en.com</li>
<li class="k-item" unselectable="on" data-idx="1" role="option" tabindex="-1">pra.melu@en.com</li>
<li class="k-item" unselectable="on" data-idx="2" role="option" tabindex="-1">prast.bha@en.com</li>
<li class="k-item" unselectable="on" data-idx="3" role="option" tabindex="-1">prp@savant.com</li>
</ul>
</div>



I try to automate above code its not working 

我使用了这段代码

    dr.findElement(By.id("from-list")).findElement(By.id("from_listbox")).click(); 
    List<WebElement> liList = dr.findElements(By.id("from_listbox"));
     liList.get(0).click(); 
     liList.get(1).click(); 

如果有任何想法,请告诉我

2 个答案:

答案 0 :(得分:0)

int liSize = driver.findElements(By.xpath(".//*[@id='from_listbox']/li")).size();
for(int j = 1; j <= liSize; j++) {
    String liLocator = String.format(".//*[@id='from_listbox']/li[%d]", j);
    driver.findElement(By.xpath(liLocator)).click();
}

答案 1 :(得分:0)

问题出现在XPATH结束之前我没有添加(/ li) 在我看到你的消息后,我添加了(/ li)。工作正常。

列表listItems = dr.findElements(By.xpath(&#34; .//*@ id =&#39; from_listbox&#39;] / li&#34;)); listItems2.get(0)。单击();