[英]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.