Sergii
Sergii

Reputation: 1027

How to choose an element from drop down with watir, that is NOT visible

I write test task and have an error

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

Here is code from 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

Before steps

@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

Browser IE9. With FF it works just fine. If i choose visible element (e.g. Alfa) it works. That is really strange. Is it necessary to scroll down to get my element?

Upvotes: 0

Views: 1278

Answers (1)

orde
orde

Reputation: 5283

You could increase the height of the dropdown, which should allow IE to access the initially obscured options. For example:

b.button(id: "ctl00_SampleContent_ComboBox1_ComboBox1_Button").click
b.execute_script("document.getElementById('ctl00_SampleContent_ComboBox1_ComboBox1_OptionList').style.height='1000px';")

Upvotes: 1

Related Questions