Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
735 views
in Technique[技术] by (71.8m points)

java - Make a page wait for 15 minutes

I want to make a page wait for 15 minutes but neither Thread.sleep or Web driver wait seems to be working.Can anyone suggest a solution for my problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you are looking to make a Web Page wait for 15 minutes, Thread.sleep(); or WebDriverWait are not the intended ways. To make the Web Page wait you have to inject Javascript within the Web Browser

As you tried Thread.sleep() and WebDriverWait, here are a few details :

  • Thread.sleep() : Is a Java based method from Thread Class which holds any further execution of a thread for the specified amount of time.
  • WebDriverWait : Is a Selenium based Class which extends org.openqa.selenium.support.ui.FluentWait<WebDriver> and is a specialization of FluentWait that uses WebDriver instances and is invoked over WebElements to attain a certain characteristics over a period of timespan.

From your question, I am not sure about the problem you are facing with Thread.sleep(); or WebDriverWait but Thread.sleep(); seems works fine for 15 minutes as follows :

Sample Program :

package demo;

public class SLEEP 
{
    public static void main(String[] args) throws InterruptedException 
    {    
        System.out.println("Program Started");
        Thread.sleep(1000*60*1);
        System.out.println("Program Ended");
    }
 }

Console Output :

Program Started
Program Ended

Note : However while working with Selenium, Thread.sleep(); should be avoided as it degrades the Test Performance. Instead we must use ExpectedConditions with a proper method from this list.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...