Nikita Soni
Nikita Soni

Reputation: 1

Stale element reference: stale element not found in the current frame

public static void selectMessageType() throws InterruptedException {
        Thread.sleep(1000);
        messageType.click();
        String[] values = {
                "Pre-arbitration case",
                "Fee collection",
                "Fee collection ATM",
                "Fee collection CCBP",
                "Fee collection POS",
                "First chargeback",
                "Retrieval request",
                "Retrieval request acknowledgement",
                "Second presentment",
                "Unknow"
        };
//           for(int i=0; i<values.length; i++){
//            driver.findElement(xpath("//span[normalize-space()='"+values[i]+"']")).click();
//            Thread.sleep(1000);
//            clicksOnSearchButton();
//            Thread.sleep(3000);
//            messageType.click();
//        }
        
        for(WebElement option: options){
                String name =option.getText();
                System.out.println(name);
                Thread.sleep(1000);
//                option.click();
            driver.findElement(xpath("//span[normalize-space()='"+option.getText()+"']")).click();
                Thread.sleep(1000);
                clicksOnSearchButton();
                Thread.sleep(3000);
                messageType.click();

        }

There are 10 options in a dropdown, which I'm trying to select each options and then click on search button one by one. But if I store these in values in an array and then iterating through each option, then its working, and if I use List options to store all elements and then iterating through for each loop, so its only selecting the first dropdown option, and then its failing and showing stale exception.

Expected: I want that it will select each dropdown option and then click search button

Upvotes: 0

Views: 209

Answers (0)

Related Questions