[英]Watir screenshot - select options not captured
我們使用watir腳本來測試我們的網站。 在測試帶有選擇標簽的頁面時,我們可以單擊選擇元素,然后在瀏覽器中看到顯示的選項。 截屏時,輸出與在瀏覽器中看到的輸出不匹配-選項丟失,選擇框突出顯示。
我們如何使選項元素在屏幕截圖中可見?
test_select.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<select id="testme">
<option>one</option>
<option>two</option>
<option>three</option>
</select>
</body>
</html>
test_select.rb:
require 'watir-webdriver'
b = Watir::Browser.new
b.goto 'file://'+Dir.pwd+'/test_select.html'
b.element(:css => 'select#testme').click
b.screenshot.save 'clicked_select.png'
為選擇列表設置屬性大小的主要思想。 此方法將更改頁面的外觀,但據我所知,這是在屏幕截圖上查看選項的唯一方法。
require 'watir-webdriver'
b = Watir::Browser.new
b.goto 'file://'+Dir.pwd+'/test_select.html'
options = b.elements(xpath: "//*[@id='testme']/option")
select_list = b.element(css: 'select#testme')
size = options.length
script = "return arguments[0].size = #{size}"
b.execute_script(script, select_list)
b.screenshot.save 'clicked_select.png'`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.