繁体   English   中英

带有 ruby​​ 和 watir 网址的整页屏幕截图

[英]Full-page screenshot with URL in ruby ​and watir

使用下面的代码,我只获得了屏幕一部分的屏幕截图,但我想截取完整的屏幕截图,其中还显示了页面的 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)

在我使用 URL 捕获全屏截图的情况下,我执行以下操作

#Code to capture the Full-Page screenshot with URL require 'watir' require 'win32ole' require 'win32/screenshot'

#Launch Browser and navigate to page browser = Watir::Browser.new :ie browser.goto "https://www.google.com"

#Fetch the Title win_title = browser.title

#Use AutoIt to get the focus of the browser to front WIN32OLE.new("AutoItX3.Control").ControlFocus(win_title, "", "")

sleep 2 # Hold for 2s image_path = "image_path#{rand(10000)}.png" Win32::Screenshot::Take.of(:desktop).write(image_path) #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) #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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM