【问题标题】:Taking screenshot of particular div element including the area inside scroll region using selenium and python使用 selenium 和 python 截取特定 div 元素的屏幕截图,包括滚动区域内的区域
【发布时间】:2014-09-03 20:36:20
【问题描述】:

我需要截取特定给定 dom 元素的屏幕截图,包括滚动区域内的区域。

我尝试使用 selenium 截取整个网页的屏幕截图,并使用 Python Imaging Library 裁剪图像,尺寸由 selenium 提供。但我想不出一种方法来捕获滚动区域下的区域。

例如,我的页面中有一个类元素容器,它的高度是根据内容动态变化的。我需要完全截取它。但是生成的图像会跳过滚动条内的区域,并且裁剪后的图像结果中只有滚动条

有没有办法做到这一点?最好使用硒溶液,如果不能用硒替代溶液也可以。

【问题讨论】:

    标签: python selenium screenshot python-imaging-library


    【解决方案1】:

    您可以使用 driver.execute_script 方法滚动,然后截图。

    我使用 jQuery 以这种方式滚动一些模态窗口:

    driver.execute_script("$('.ui-window-wrap:visible').scrollTop(document.body.scrollHeight);")

    【讨论】:

      猜你喜欢
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 2016-04-06
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      • 2012-01-31
      • 1970-01-01
      相关资源
      最近更新 更多