1

I have a StaleElementReferenceException.

I found How to avoid "StaleElementReferenceException" in Selenium?. I tried to understand and fit it to my code.

By ordersBy = (By.id("subtab-AdminParentOrders"));
        WebElement orders = driver.findElement(ordersBy);
        orders.click();
        public boolean retryingFindClick () {
            boolean result = false;
            int attempts = 0;
            while (attempts < 2) {
                try {
                    driver.findElement(By.id("subtab-AdminParentOrders")).click();
                    result = true;
                    break;
                } catch (StaleElementReferenceException e) {
                }
                attempts++;
            }
            return result;
        }

First compilation error. What should I paste as argument? Why is a semicolon expected?

enter image description here

I wrote this method in main. Maybe that is why return is denied. How can I adapt this method to my code (in main)?

enter image description here

Community
  • 1
  • 1
  • If you really are trying to define a method inside bory of another method, then: you can't do that. Method would be defined somewhere outside. And please don't post images. Post actual code instead. – M. Prokhorov Sep 28 '17 at 17:47

1 Answers1

0

The way I see it you have created a method inside another method, it doesn't work like that. Also get retryingFindClick() out into class body and Just replace try code with following, it should work:

try{
         WebElement elem = driver.findElement(By.id("subtab-AdminParentOrders"));
         elem.click();
         result = true;
         break;
   }
   ...
Kushal Bhalaik
  • 3,349
  • 5
  • 23
  • 46