ruby - 带有 ruby 和 watir 中的 URL 的整页屏幕截图
问题描述
使用下面的代码,我只截取了屏幕的一部分,但我想截取完整的截图,其中还显示了页面的 URL。
可能吗?
AfterStep do
encoded_img = @browser.driver.screenshot_as(:base64)
embed("data:image/png;base64,#{encoded_img}",'image/png')
end
解决方案
Watir 没有此规定来捕获屏幕截图和 URL。但是我们可以使用 win32ole 来做到这一点。
require 'win32/screenshot'
Win32::Screenshot::Take.of(:desktop).write(image_path)
在我使用 URL 捕获全屏截图的情况下,我执行以下操作
# Code to capture the full-page screenshot with a URL
require 'watir'
require 'win32ole'
require 'win32/screenshot'
# Launch a browser and navigate to the page
browser = Watir::Browser.new :ie
browser.goto "https://www.google.com"
win_title = browser.title #Fetch the Title
# Use AutoIt to get the focus of the browser to front
WIN32OLE.new("AutoItX3.Control").ControlFocus(win_title, "", "")
# Capture the screen shot of the desktop
sleep 2 # Hold for 2s
image_path = "image_path#{rand(10000)}.png"
Win32::Screenshot::Take.of(:desktop).write(image_path)
推荐阅读
- python - SQLAlchemy AttributeError:“int”对象没有属性“_set_parent_dispatch”
- nestjs - 使用装饰器时,Nestjs 无法解析依赖索引 [0]
- python - 无法在我的 Windows 10 64 位上使用 pip 安装 scrapy
- java - 我将如何获得路径?
- unity3d - 如何创建自定义 GridLayout
- sql - 如何将单位显示为同一显示订单的第二个显示项目?
- python - 将变量作为参数传递给 selenium find_element 函数而不是硬编码参数会导致 InvalidArgumentException
- java - Spring CSRF 使手动登录会话无效
- c++ - ubuntu 20.04 上的 Visual Studio 代码。c++ 语法检查器无法正常工作
- php - 无法在laravel中上传larage大小的pdf文件