Create a new <WebElement> and put the items from your original list to the new one applying the logic of re-ordering you need.

If you need to keep the reference name, you can just redefine the old reference to the new object like:

List<WebElement> element = ul.findElements(By.tagName("li"));
List<WebElement> reOrderedElement = new ArrayList<WebElement>();

// Put  from element to reOrderedElement
// using the logic you imply

element = reOrderedElement;

Another option might work well if the information required for the reordering is the property of the list items themselves. If this is your case you can just do the following (with no need to create a separate list):

    element.sort(new Comparator<WebElement>() {
        @Override
        public int compare(WebElement o1, WebElement o2) {
            // TODO: implement sorting logic here
        }
    });

Where TODO expects from you to describe the logic of sorting. For details on Comparator feel free to learn corresponding JavaDocs



Source link https://sqa.stackexchange.com/questions/35286/how-to--elements-in-a-list-of-

LEAVE A REPLY

Please enter your comment!
Please enter your name here