我编写测试任务并出错
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
这是来自Cucumber的代码
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),它就可以了。这真的很奇怪。是否有必要向下滚动才能获得我的元素?
答案 0 :(得分:1)
您可以增加下拉列表的高度,这应该允许IE访问最初隐藏的选项。例如:
b.button(id: "ctl00_SampleContent_ComboBox1_ComboBox1_Button").click
b.execute_script("document.getElementById('ctl00_SampleContent_ComboBox1_ComboBox1_OptionList').style.height='1000px';")