我的网页包含2 list boxes
左侧&右转移箭头。
我需要select an item from left
并点击箭头,以便它移至rigtside list box
。
我的代码如下所示,但它无效。
List<WebElement> li = driver.findElements(By.xpath(".//*[@id='availableClients']/div/ul"));
for (WebElement lit : li)
{
System.out.println(lit.getText());
if (lit.getText().equalsIgnoreCase("CHKD"))
{
lit.click();
break;
}
}
HTML来源
<div id="availableClients" class="left"> <label for="Available_Clients">Available Clients</label> <div class="list-swap-left"> <span style="width:0"/> <ul class="list-swap-list ui-sortable" title="Select the client to have access to this help link"> <li id="1" class="">abc</li> <li id="22" class="">CHKD</li> <li id="83" class="">Peg</li> <li id="95" class="">Sale</li>
答案 0 :(得分:0)
最后我自己得到了解决方案:
// To Select the Item from List Box
WebElement xps = driver.findElement(By.xpath(xpath));
List<WebElement> sli = xps.findElements(By.tagName("li"));
for (int i = 0; i < sli.size(); i++)
{
if (sli.get(i).getText().equalsIgnoreCase(Itemtext))
{
sli.get(i).click();
break;
}
else{System.out.println("Item not fount in the list");}
}
//Click on Arrow Icon outside the List box to move the Item
driver.findElement(By.cssSelector("i.icn.cir-fwd")).click();