Monday, November 14, 2022

While loop with specific time to wait until element get displayed in selenium C# and java

 public static void waitForOneTrust()

        {

            var stopwatch = new Stopwatch();

            stopwatch.Start();



            while (stopwatch.Elapsed < TimeSpan.FromSeconds(30))

            {

                IWebElement oneTrust = driver.FindElement(By.Id("onetrust-accept-btn-handler"));

                if (oneTrust.Displayed)

                {

                    break;

                }


            }

        }



In Java:

public void waitTillBackOfficePageLoad()
{
LocalDateTime now = LocalDateTime.now();
while (LocalDateTime.now().isBefore(now.plusSeconds(30)))
{

if(
xxxxxx)
{
break;
}

}
}

No comments:

Post a Comment