简体   繁体   中英

How to move an item from a list box using selenium webdriver

I have a web page contains 2 list boxes left & Right with transfer arrows. I need to select an item from left and click on arrow so that it will move to rigtside list box .

I did my code like below, but it is not working.

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 SOURCE

<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> 

Finally i myself got the solution:

// 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM