我正在使用下面的代码来捕捉一个网站的每一页的截图。它可以工作,但有时某些页面会延迟1到2秒/秒,我会被一个旋转的gif圈用“请等一下.”的图片轰炸。消息。
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));使用Firebug,看起来这可能是罪魁祸首:
<div class="blockUI blockMsg blockPage" style="z-index: 1011; position: fixed;
padding: 15px; margin: 0px; width: 20%; top: 40%; left: 40%; text-align: center;
color: rgb(255, 255, 255); border: medium none; background-color: rgb(0, 0, 0);
cursor: wait; opacity: 0;">
<img src="/images/front/loading.gif"/>
<br/>
<strong>Please wait...</strong>
</div>`我的问题是:我该如何安排截图的时间来避免这种情况?Thread.sleep(2000)工作,但我宁愿远离它。我还检查了页面中是否存在元素,它们就在那里,但是这条消息阻碍了我们的工作。
谢谢你的建议。谢谢。
**编辑以添加一些被切断的代码(来自Firebug)。
发布于 2013-08-08 16:11:11
你试过等到“请等.”元素是无形的?
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//strong[text()='Please wait...']"));发布于 2016-04-01 09:51:15
我们可以将其用于10+的最新版本:
wait.until(ExpectedConditions.invisibilityOfElementWithText(
By.xpath("//div[2]/div[contains(text(),'Please Wait....')]"),"Please Wait...."));https://stackoverflow.com/questions/18128050
复制相似问题