2016-01-20 91 views
1

我有以下元素:硒等元素出现,dissapear

<div class="ui-helper-hidden" id="shell.indicator.busy"> 
    <label>Processing...</label> 
    <br /> 
    <img src="/RightCrowd/Images/loading.gif" alt="" /> 
</div> 

,它似乎是这样的:

Processing

我想等待它出现,然后消失并继续访问元素。这出现在Web应用程序的大多数页面上。我们尝试了一些东西,但有时可以看到硒,有时不是,虽然我可以用我的眼睛看到它。

我相信这个处理图像出现在当前页面的顶部,并且使用当前处理程序可能没用。不确定。

我们试过这样的事情:

 WebElement element = (new WebDriverWait(webDriver, 10)) 
        .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[contains(@src,'/Images/loading.gif')]"))); 

     boolean processingEnd = (new WebDriverWait(webDriver, timeoutWaitForProgressbar)) 
        .until(ExpectedConditions.invisibilityOfElementLocated(By.id("shell.indicator.busy"))); 

所以我们都试过XPath和ID ...请让我知道什么是处理这种情况的最好办法。

+0

当您使用xpath和ID尝试它时发生了什么?它是否抛出异常?哪个例外? –

+0

这是一个TimeoutException。代码尝试捕获,但我没有复制粘贴所有内容。我有兴趣在它出现时正确检测,并检测它何时消失。 –

+0

等待它出现或等待其消失的超时时间?如果你遇到超时,它最终会发现它吗? –

回答

3

默认情况下,WebDriverWait将每隔半秒检查一次预期状态状态。我会尝试更频繁地使用FluentWait类发出预期的状态检查请求:

Wait wait = new FluentWait(driver) 
    .withTimeout(timeoutWaitForProgressbar, SECONDS) 
    .pollingEvery(100, MILLISECONDS); 

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("shell.indicator.busy"))); 
+0

作为评论,pollingEvery不接受double值,但我可以使用毫秒。还是行不通。我会等待别人回复... –

+0

现在比较稳定。我使用xpath(例如By.xpath(“// img [contains(@src,'/ Images/loading.gif')]”))而不是id,现在看起来更一致。 –

+0

fluentwait页面无法正常工作 –