【问题标题】:Thread.sleep not running [duplicate]Thread.sleep 未运行 [重复]
【发布时间】:2018-12-21 23:20:54
【问题描述】:

我在 Eclipse 中有一些具有以下结构的代码:

package automationFramework;

import java.util.List;
import org.openqa.selenium.support.ui.Select;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FirefoxDropDown {

    public static void main(String[] args) throws InterruptedException {
        // Create a new instance of the Firefox driver

        System.setProperty("webdriver.gecko.driver", "/home/gradulescu/Documents/Eclipse project/geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        // Storing the Application URL in the String variable
        String url= "http://toolsqa.wpengine.com/automation-practice-form/";
        driver.get(url);        
        //Launch the Online Store Website
        Select oSdropDown = new Select((WebElement)driver.findElement(By.id("continents")));
        oSdropDown.selectByIndex(1);
        Thread.sleep(100);
        oSdropDown.selectByVisibleText("Africa");
        Thread.sleep(100);
        List<WebElement> oSize = oSdropDown.getOptions();
        int size = oSize.size();
        for(int i=0;i<size;i++)
        {
            String sValue = oSdropDown.getOptions().get(i).getText();

            System.out.println(sValue);

        }           
        driver.quit();

    }   
}

我的期望是在第一个代码运行后,等待 10 秒,然后是第二个代码,再等 10 秒。但实际上编译器在命令后运行命令而不等待我设置的 10 秒。

它是否有任何强制条件才能工作?

谢谢!

【问题讨论】:

  • 不要假设库方法的作用。阅读它的 javadoc。它说 毫秒
  • 那么:这与您在此处使用的大多数标签没有任何关系。请仅使用有意义的标签。您选择的 IDE 肯定与编程问题无关。

标签: java sleep


【解决方案1】:

我觉得你等的时间不够长,试试:Thread.sleep(10000);

您也可以使用:Thread.sleep(TimeUnit.SECONDS.toMillis(10));

【讨论】:

  • 好吧,它似乎奏效了。我认为睡眠是以秒计算的,而不是毫秒。或者至少这是我正在阅读的教程中所说的。谢谢。 :)
  • 没问题,很乐意提供帮助。
  • 甚至TimeUnit.SECONDS.sleep(10);
猜你喜欢
  • 1970-01-01
  • 2021-12-22
  • 1970-01-01
  • 2012-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-01
相关资源
最近更新 更多