嗨,我正在尝试在硒测试中使用 webdriver。我想检查它是如何工作的。我给了 5 秒作为 webdriver 等待的最长时间。我的页面加载时间超过 7 秒,但我仍然没有从 webdriver 等待中得到任何超时异常。我也在给我的控制台输出。请告诉我为什么我没有收到超时异常?
public class MainClass {
private static ChromeDriver driver;
public static void main(String[] args) {
executeTest();
}
private static void executeTest( ) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
driver = new ChromeDriver();
// driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.get("http://myUrl");
Long loadtime = (Long) ((JavascriptExecutor) driver)
.executeScript("return performance.timing.loadEventEnd - performance.timing.navigationStart;");
System.out.println("loadding time " + Loadtime);
WebDriverWait wait = new WebDriverWait(driver, 5);
Boolean sign_in = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("signinbutton")))
.isDisplayed();
if (sign_in == true) {
driver.findElement(By.id("signinbutton")).click();
} else {
System.out.println("Oops! Couldn't locate sign_in element!");
}
Boolean user_name = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username_id")))
.isDisplayed();
// user_name.sendKeys("ANAND@RIL");
if (user_name == true) {
driver.findElement(By.id("username_id")).sendKeys("ANAND@RIL");
} else {
System.out.println("Oops! Couldn't locate user_name element!");
}
Boolean password = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("password_id")))
.isDisplayed();
if (password == true) {
driver.findElement(By.id("password_id")).sendKeys("ANAND");
} else {
System.out.println("Oops! Couldn't locate password element!");
}
WebElement login =
wait.until(ExpectedConditions.elementToBeClickable(By.id("textButton")));
login.click();
}
}
控制台输出:
尝试 1:
Starting ChromeDriver 2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91) on port 42020
Only local connections are allowed.
Apr 18, 2018 12:07:35 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
**Loading time 7872**
尝试 2:
Starting ChromeDriver 2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91) on port 38325
Only local connections are allowed.
Apr 18, 2018 12:07:46 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
**Loadding time 6632**
尝试 3:
Starting ChromeDriver 2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91) on port 34619
Only local connections are allowed.
Apr 18, 2018 12:07:55 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
**Loadding time 7522**
尝试 4:
Starting ChromeDriver 2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91) on port 48000
Only local connections are allowed.
Apr 18, 2018 12:08:05 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS