简体   繁体   English

Watir屏幕截图-未捕获选择的选项

[英]Watir screenshot - select options not captured

We use watir scripts to test our website. 我们使用watir脚本来测试我们的网站。 When testing pages with select tags, we have watir click the select element and can see the options display in the browser. 在测试带有选择标签的页面时,我们可以单击选择元素,然后在浏览器中看到显示的选项。 When we take a screenshot, the output does not match what we see in the browser - the options are missing, instead the select box is highlighted. 截屏时,输出与在浏览器中看到的输出不匹配-选项丢失,选择框突出显示。

What can we do to make the option elements visible in the screenshot? 我们如何使选项元素在屏幕截图中可见?

test_select.html 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: 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'

The main idea to set attribute size for your select list. 为选择列表设置属性大小的主要思想。 This method will change appearance of the page but as far as I know it is the only way to see options on the screenshot. 此方法将更改页面的外观,但据我所知,这是在屏幕截图上查看选项的唯一方法。

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.

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