让页面等待15分钟 [英] Make a page wait for 15 minutes

查看:126
本文介绍了让页面等待15分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让页面等待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 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.

根据您的问题,我不确定您遇到的是 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 the Test Performance. Instead we must use ExpectedConditions with a proper method from this list.

这篇关于让页面等待15分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆