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

1 like 0 dislike
1.7k views
by The go-to Tester (391 points)
edited by
Here goes my class:

public void clickAroLoadKorunLink() throws InterruptedException
    {
        
        do{
        WebDriverWait waitLoadMore = new WebDriverWait(driver, 25);
        waitLoadMore.until(ExpectedConditions.elementToBeClickable(AroLoadKorunLink));
        JavascriptExecutor exe = (JavascriptExecutor)driver;
        WebElement eleAroLoadKorunLink = driver.findElement(AroLoadKorunLink);
        exe.executeScript("arguments[0].scrollIntoView(true);", eleAroLoadKorunLink );
        exe.executeScript("arguments[0].click();", eleAroLoadKorunLink );
       
        Thread.sleep(5000);
        if(!(driver.findElement(AroLoadKorunLink).isDisplayed()))
        {
            break;
        }
            
            
        }while(driver.findElement(AroLoadKorunLink).isDisplayed());

    }
by The go-to Tester (391 points)
My code is working fine but the exit condition is not working.
by The go-to Tester (181 points)
What is the error that you're getting?
by The go-to Tester (391 points)
I am not getting any error, only the test case fails as the script is still searching for the load more button

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)

There are possibilitis that AroLoadKorunLink is displayed. But not clickable.

 

Do you want to try using driver.findElement(AroLoadKorunLink).isEnabled() or isClickable?

 

To see if element is clickable you may have to use below custom function for isClickable.

 
public static boolean isClickable(WebElement webe)
 
{
try
{
   WebDriverWait wait = new WebDriverWait(yourWebDriver, 5);
   wait.until(ExpectedConditions.elementToBeClickable(webe));
   return true;
}
catch (Exception e)
{
  return false;
}
}

 

Hope tha thelps.

by The go-to Tester (391 points)
Is it mandatory to declare the isClickable() method as static?
by The go-to Tester (181 points)
No. You can use it as non static.


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!

1.4k questions

1.6k answers

866 comments

1.9k users

...