让页面等待15分钟 [英] Make a page wait for 15 minutes
问题描述
我想让页面等待15分钟,但是Thread.sleep或Web驱动程序等待似乎都不起作用.有人可以为我的问题提供解决方案吗?
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?
推荐答案
如果要让Web Page
等待15分钟,请 Thread.sleep();
或 WebDriverWait
并非预期的方式.要等待Web Page
,您必须在 Web Browser
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
在尝试 Thread.sleep()
和 WebDriverWait
时,以下是一些详细信息:
As you tried Thread.sleep()
and WebDriverWait
, here are a few details :
-
Thread.sleep()
:是Thread Class
中基于Java
的方法,该方法可在指定的时间内保存线程的任何进一步执行. -
WebDriverWait
:是基于Selenium
的Class
,它扩展了org.openqa.selenium.support.ui.FluentWait<WebDriver>
,并且是FluentWait
的特殊化,它使用WebDriver
实例,并在WebElements
上被调用以在一段时间内达到某些特征.
Thread.sleep()
: Is aJava
based method fromThread Class
which holds any further execution of a thread for the specified amount of time.WebDriverWait
: Is aSelenium
basedClass
which extendsorg.openqa.selenium.support.ui.FluentWait<WebDriver>
and is a specialization ofFluentWait
that usesWebDriver
instances and is invoked overWebElements
to attain a certain characteristics over a period of timespan.
根据您的问题,我不确定您遇到的是 Thread.sleep();
或 WebDriverWait
所遇到的问题,但是 Thread.sleep();
似乎对于 15 minutes
来说可以正常工作,如下所示:
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 :
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");
}
}
控制台输出:
Program Started
Program Ended
注意:但是,在使用
Selenium
时,应避免使用Thread.sleep();
,因为它会降低Test Performance
.相反,我们必须通过此
Note : However while working with
Selenium
,Thread.sleep();
should be avoided as it degrades theTest Performance
. Instead we must useExpectedConditions
with a proper method from thislist
.
这篇关于让页面等待15分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!