Skip to content
This repository
Browse code

improved the way I select options from select lists

  • Loading branch information...
commit 5220cf6e9ba8700d2a961356fb5aa65bb4f851ad 1 parent 29254f7
Jeff Morgan authored
2  ChangeLog
... ... @@ -1,6 +1,8 @@
1 1 === Version 0.6.7
2 2 * Enhancements
3 3 * Updated to use watir-webdriver 0.5.7
  4 +* Fixes
  5 + * Improved logic around selecting options from select lists
4 6
5 7 === Version 0.6.6 / 2012-4-26
6 8 * Enhancements
5 lib/page-object/platforms/selenium_webdriver/page_object.rb
@@ -297,7 +297,10 @@ def select_list_value_for(identifier)
297 297 #
298 298 def select_list_value_set(identifier, value)
299 299 process_selenium_call(identifier, Elements::SelectList, 'select') do |how, what|
300   - @browser.find_element(how, what).send_keys(value)
  300 + select_list = @browser.find_element(how, what)
  301 + select_list.find_elements(:tag_name => 'option').find do |option|
  302 + option.text == value
  303 + end.click
301 304 end
302 305 end
303 306
4 lib/page-object/platforms/selenium_webdriver/select_list.rb
@@ -17,7 +17,9 @@ def [](idx)
17 17 # Select a value from the list
18 18 #
19 19 def select(value)
20   - element.send_keys(value)
  20 + find_options.find do |option|
  21 + option.text == value
  22 + end.click
21 23 end
22 24
23 25 #
5 spec/page-object/accessors_spec.rb
@@ -607,8 +607,11 @@ def mock_driver_for(tag)
607 607 end
608 608
609 609 it "should set the current item of a select list" do
  610 + option = double('option')
610 611 selenium_browser.should_receive(:find_element).and_return(selenium_browser)
611   - selenium_browser.should_receive(:send_keys).with("OH")
  612 + selenium_browser.should_receive(:find_elements).and_return([option])
  613 + option.should_receive(:text).and_return('OH')
  614 + option.should_receive(:click)
612 615 selenium_page_object.state = "OH"
613 616 end
614 617
5 spec/page-object/elements/select_list_spec.rb
@@ -83,7 +83,10 @@
83 83 end
84 84
85 85 it "should select an element" do
86   - sel_list.should_receive(:send_keys).with('something')
  86 + option = double('option')
  87 + sel_list.should_receive(:find_elements).with(:xpath, ".//child::option").and_return([option])
  88 + option.should_receive(:text).and_return('something')
  89 + option.should_receive(:click)
87 90 selenium_sel_list.select 'something'
88 91 end
89 92

0 comments on commit 5220cf6

Please sign in to comment.
Something went wrong with that request. Please try again.