Java Selenium WebDriver 中 selenium.waitForPageToLoad("30000") 的等效代码是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18378533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the equivalent code of selenium.waitForPageToLoad("30000") in Selenium WebDriver?
提问by Ripon Al Wasim
The following is the java code to wait for a page loading in Selenium RC:
以下是在 Selenium RC 中等待页面加载的 java 代码:
selenium.waitForPageToLoad("30000");
What is the equivalent java code in Selenium WebDriver?
Selenium WebDriver 中的等效 java 代码是什么?
采纳答案by praneel
2 approaches:
2种方法:
If you need to wait exactly 60 sec you could use Thread.sleep(60000)
If you want to make sure that the page is loaded (it could be less than or greater than 60 sec) I would recommend the below approach:
如果您需要等待 60 秒,您可以使用 Thread.sleep(60000)
如果您想确保页面已加载(可能小于或大于 60 秒),我会推荐以下方法:
Identify an element in the landing page & wait for it to be clickable. You are then sure that the page has been loaded.
识别登陆页面中的一个元素并等待它被点击。然后您确定该页面已加载。
WebDriverWait wait = new WebDriverWait(driver,120);
wait.until(ExpectedConditions.elementToBeClickable(By.id(id)));
WebDriver waits for a max of 120 sec. for the element to be clickable. If the element is clickable before that, your test would progress.
WebDriver 最多等待 120 秒。使元素可点击。如果该元素在此之前可点击,则您的测试将继续进行。
回答by Nth-Tester
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);