0

我写了测试任务并且有一个错误

Scenario: Set "Whiskey" value from dropdown menu                                           # features\task2.feature:10
    Given I am on the page with "ComboBox" example                                           # features/step_definitions/task2.rb:13
    When I choose "Whiskey" from drop down menu                                              # features/step_definitions/task2.rb:16
      Cannot click on element (Selenium::WebDriver::Error::ElementNotVisibleError)
      ./features/step_definitions/task2.rb:19:in `/^I choose "(.*?)" from drop down menu$/'
      features\task2.feature:12:in `When I choose "Whiskey" from drop down menu'
    And I click "Submit" button                                                              # features/step_definitions/task2.rb:22
    Then I should see "You changed your selection to: 'Whiskey' " text displeyed on the page # features/step_definitions/task2.rb:26

这是黄瓜的代码

When /^I choose "(.*?)" from drop down menu$/ do |drop_down_text|  
  @browser.button(id: "ctl00_SampleContent_ComboBox1_ComboBox1_Button").click  
  @browser.ul(id: "ctl00_SampleContent_ComboBox1_ComboBox1_OptionList").li(text: drop_down_text).click
end

步骤之前

@browser.goto http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/Default.aspx"
@browser.link(:text, ComboBox).click
@browser.button(id: "ctl00_SampleContent_ComboBox1_ComboBox1_Button").click

浏览器 IE9。使用 FF 就可以了。如果我选择可见元素(例如 Alfa),它会起作用。这真的很奇怪。是否需要向下滚动才能获取我的元素?

4

1 回答 1

1

您可以增加下拉菜单的高度,这应该允许 IE 访问最初被隐藏的选项。例如:

b.button(id: "ctl00_SampleContent_ComboBox1_ComboBox1_Button").click
b.execute_script("document.getElementById('ctl00_SampleContent_ComboBox1_ComboBox1_OptionList').style.height='1000px';")
于 2013-01-30T18:53:02.783 回答