Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
173 views
by

 have a Search Screen where after I enter the search criteria and search a Load More button will display if there are more than 30 records. The problem is it clicks the Load more button but leads to stale element Exception

The scenario is I need to click till the Load More button becomes disabled.

Below is my code any inputs

WebElement loadmoreElems = DriverUtil.getFluentWaitElementByXPath(loadmoreXpath,20, driver);
do
                {
                
                WebDriverWait wait = new WebDriverWait(driver,10);
                wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[contains(@class,'mat-button-wrapper') and contains(normalize-space(),'Load More')]")));
                loadmoreElems.click(); - **The click Element leads to stale Element Exception**
                loadmoreElems = DriverUtil.getFluentWaitElementByXPath(loadmoreXpath,20, driver);
                if(!loadmoreElem.isDisplayed())
                {
                
                break;

            } }
                while(loadmoreElem.isDisplayed());
         }
    }

StackTrace: org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document (Session info: chrome=93.0.4577.82) For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html Build info: version: '3.14.0', revision: 'aacccce0', tim Is there anyways to get this working

1 Answer

0 like 0 dislike
by Master (1.2k points)
Yes. You need to reassign element references.

Try extending wait time to 50 seconds or 150 seconds.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...