Browse files

improved the way I select options from select lists

  • Loading branch information...
1 parent 29254f7 commit 5220cf6e9ba8700d2a961356fb5aa65bb4f851ad @cheezy committed May 13, 2012
View
2 ChangeLog
@@ -1,6 +1,8 @@
=== Version 0.6.7
* Enhancements
* Updated to use watir-webdriver 0.5.7
+* Fixes
+ * Improved logic around selecting options from select lists
=== Version 0.6.6 / 2012-4-26
* Enhancements
View
5 lib/page-object/platforms/selenium_webdriver/page_object.rb
@@ -297,7 +297,10 @@ def select_list_value_for(identifier)
#
def select_list_value_set(identifier, value)
process_selenium_call(identifier, Elements::SelectList, 'select') do |how, what|
- @browser.find_element(how, what).send_keys(value)
+ select_list = @browser.find_element(how, what)
+ select_list.find_elements(:tag_name => 'option').find do |option|
+ option.text == value
+ end.click
end
end
View
4 lib/page-object/platforms/selenium_webdriver/select_list.rb
@@ -17,7 +17,9 @@ def [](idx)
# Select a value from the list
#
def select(value)
- element.send_keys(value)
+ find_options.find do |option|
+ option.text == value
+ end.click
end
#
View
5 spec/page-object/accessors_spec.rb
@@ -607,8 +607,11 @@ def mock_driver_for(tag)
end
it "should set the current item of a select list" do
+ option = double('option')
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
- selenium_browser.should_receive(:send_keys).with("OH")
+ selenium_browser.should_receive(:find_elements).and_return([option])
+ option.should_receive(:text).and_return('OH')
+ option.should_receive(:click)
selenium_page_object.state = "OH"
end
View
5 spec/page-object/elements/select_list_spec.rb
@@ -83,7 +83,10 @@
end
it "should select an element" do
- sel_list.should_receive(:send_keys).with('something')
+ option = double('option')
+ sel_list.should_receive(:find_elements).with(:xpath, ".//child::option").and_return([option])
+ option.should_receive(:text).and_return('something')
+ option.should_receive(:click)
selenium_sel_list.select 'something'
end

0 comments on commit 5220cf6

Please sign in to comment.