【问题标题】:How to wait untill a page is dim after clicking a button?单击按钮后如何等到页面变暗?
【发布时间】: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


【解决方案1】:

等到加载框不可见。 假设Loading box的locator/id/xpath为id = loader,则

By locator = By.id("loader");
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)  
                    .withTimeout(timeOutInSeconds, TimeUnit.SECONDS)                    
                    .pollingEvery(pollingIntervalInSeconds, TimeUnit.SECONDS)            
                    .ignoring(NoSuchElementException.class)                     
                    .ignoring(StaleElementReferenceException.class);                    
            wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-11
    • 1970-01-01
    • 1970-01-01
    • 2021-06-15
    • 2019-08-22
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    相关资源
    最近更新 更多