javascript - Selenium - 等待 ScrollIntoView 完成
问题描述
我需要滚动到一个元素并截取页面的屏幕截图,但驱动程序在页面完全滚动到该元素之前截取了屏幕截图。我用这种方式睡了一段时间
driver.execute_script("""arguments[0].scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });""", element)
time.sleep(1)
scr = driver.get_screenshot_as_png()
但我真的不想使用睡眠,因为它们不是面向测试的。我试图等待元素可见,但它也不起作用。另一种尝试是使用 ActionChains 移动到元素,但它没有显示整个元素在其上移动。有没有办法等待滚动完成?除了屏幕截图的这种特定情况之外,了解等待滚动完成的方法会很有用。
解决方案
public static void fullScren(String filename) throws IOException
{
Screenshot myScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver);
ImageIO.write(myScreenshot.getImage(),"PNG",new File("src/main/java/ScreenShots/" + filename + ".jpg"));
}
您必须使用此向下滚动并通过 selenium 进行全屏拍摄
推荐阅读
- java - java.lang.NoSuchMethodError:org.springframework.util.Assert.noNullElements
- aws-lambda - 无服务器 alb 事件没有查询参数作为具有 multiValueQueryStringParameters: true 的列表
- macos - nuget sign 命令在 Mac 上使用 NU3018 失败
- r - If 语句导致闪亮应用程序中的 downloadhandler() 出现问题
- python - 为我的不和谐服务器制作 !suggest 命令,并需要它给我,所有者。可以dm特定的人吗?
- c++ - io_context 到底是什么?
- sql - 获取缺失日期的缺失记录并使用之前的非 Null 值更新值
- python - Python peewee:如何在连接之前在一列上选择不同的值?
- ffmpeg - 使用 ffmpeg 将视频从 30fps 重新编码到 60fps
- php - 如何在 Laravel 中使用另一个字段进行身份验证?