I 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 here is it clicks the Load More button for the first time but is not clicking a second or third time.
The scenario is I need to click until the Load More button becomes disabled.
Below is my code any inputs
List<WebElement> rows = driver.findElements(By.xpath("//tbody[@role='rowgroup']/tr"));
int rowcount = rows.size();
String loadmoreXpath = AppXPathsConstants.buttonXpath_replace.replace("XXXX","Load More");
if(driver.findElements(By.xpath(loadmoreXpath)).size()!= 0)
{
WebElement loadmoreElem = DriverUtil.getFluentWaitElementByXPath(loadmoreXpath,20, driver);
do
{
WebDriverWait wait = new WebDriverWait(driver,60);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(@class,'mat-button-wrapper') and contains(normalize-space(),'Load More')]")));
loadmoreElem.click();
DriverUtil.waitTime(6000);
WebDriverWait w = new WebDriverWait(driver,10);
w.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(loadmoreXpath)));
}
while(driver.findElements(By.xpath("//span[contains(@class,'mat-button-wrapper') and contains(normalize-space(),'Load More')]")).size()>0);
}
And on running the code i get the below issue:
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to no longer be visible: By.xpath: //span[contains(@class,'mat-button-wrapper') and contains(normalize-space(),'Load More')] (tried for 10 second(s) with 500 milliseconds interval)