【问题标题】:how to check text color in watir for drop down boxes attributes如何检查 watir 中的文本颜色以获取下拉框属性
【发布时间】:2012-02-11 01:35:13
【问题描述】:
contents = $ie.select_list(:id, "dropdown").getAllContents
puts contents.currentstyle.color

错误显示为

1) Error:
test_01(TC_Login):
NoMethodError: undefined method `currentstyle' for

任何人都可以帮忙,因为我需要获取具有特定颜色的特定记录

【问题讨论】:

  • 最好看html和css。也许样式不是为下拉内容设置的,而是下拉列表本身。无论如何,这是人们可以帮助您的信息。

标签: ruby automation watir


【解决方案1】:

假设你有这样的 HTML:

<select name="list" id="select_list">
  <option value="1" style="color:blue" SELECTED>Name1</option>
  <option value="2" style="color:green">Name2</option>
  <option value="3" style="color:green">Name3</option>
</select>

我发现获得选项颜色的唯一方法是直接访问它(从 win32ole 对象)。以下将输出第一个选项的颜色。

puts $ie.select_list(:id, "dropdown").document.options(0).style.color

如果你想获得具有匹配颜色的 Watir::Option 对象,你可以这样做:

matching_colour = 'green'   # Colour you want

# Iterate through the options to find the first match
select_list_element = ie.select_list(:id, 'dropdown')
matching_option = nil
select_list_element.document.options.each{ |o|
  if o.style.color == matching_colour
    matching_option = select_list_element.option(:text, o.text)
    break
  end
}

# Do something with the option if one was found
if match_option.nil?
  #Nothing matches
else
  #Do something with the option, like select it
  matching_option.select
end

【讨论】:

    猜你喜欢
    • 2011-09-06
    • 1970-01-01
    • 2020-10-18
    • 2011-04-02
    • 2010-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多