【发布时间】:2017-05-17 07:00:35
【问题描述】:
点击按钮后如何等到页面变暗(加载)?我尝试了以下选项,但尚未成功。我必须捕捉交易时间。
1) 隐式等待
(driver.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);)
2) 显式等待
(wait = new WebDriverWait(driver, 200);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//a[@ardbn='z3Btn_TDS_Next']/div/img)[position()<3]")));)
3) 我自己的功能之一
public void waitForPageLoaded() {
ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete"); } };
Wait<WebDriver> wait = new WebDriverWait(driver,30); try { wait.until(expectation); } catch(Throwable error) { fail("Timeout waiting for Page Load Request to complete."); } }
【问题讨论】:
-
您使用的术语
until a page is dim(loading)过于宽泛,无法在此回答。您能告诉我们您的确切要求或测试步骤吗?谢谢。 -
当我单击一个按钮时,整个页面变暗,并且在该事务完成后它进入正常状态。现在发生了什么,Page 处于昏暗状态,下一个事务开始,整个测试失败。我不想使用睡眠或任何其他特定的时间间隔功能,否则我无法捕获实际的交易时间。
-
从您最近的评论中,我了解到您正在尝试
capture the actual transaction time,Selenium 可能不是正确的工具。您可能想看看其他一些工具,例如SoapUI专门用于测试 Web 服务以及提供Load Test。谢谢 -
添加一个脚本来检查加载按钮的不可见性
标签: selenium selenium-webdriver