我在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秒的情况下逐个命令运行。
有任何强制性条件才能使其正常工作吗?
谢谢!
答案 0 :(得分:0)
我认为您等待的时间不够长,请尝试:Thread.sleep(10000);
您还可以使用:Thread.sleep(TimeUnit.SECONDS.toMillis(10));