I`m using Selenium, is there any way i could reduce the time taken to continue the script?



  • If the element is found it takes only around 3 seconds to move to the next code, but the script takes around 2.5 min to execute the steps if the element is not available. Is there any way that I could improve the code?

    now = LocalDateTime.now();
    logger.info("time Before IF condition confirm modal "+dtf.format(now));
    
    if (driver.findElements(By.id("navigateAwayWarningModalYes")).size() !=0){
    
    logger.info("Navigated from Single View");
    AppraisalList.clickYesFromModal();
    now = LocalDateTime.now();
    logger.info("time after confirm modal "+dtf.format(now));
    } else {
              logger.info("Navigated from Multiple View");
              now = LocalDateTime.now();
              logger.info("time after identifying confirm modal not available 
                          "+dtf.format(now));
    }
    

    now = LocalDateTime.now();

    ...enter image description here



  • As Daniel said in his comment - somewhere in your code is an Implicit wait, which is set to 2.5 minutes. I suggest you ask someone who put it there, what was the reason behind it. If that is not possible, you can set it to 0 right before your code like this:

    driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    

    and then, once you are done set it back to 2.5 minutes like this:

    driver.manage().timeouts().implicitlyWait(150, TimeUnit.SECONDS);
    

    Implicit wait will always wait a set amount of time before throwing NoSuchElementException.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2