Skip to content

Commit

Permalink
[rb] element index is a property and not an attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Oct 20, 2021
1 parent ef41797 commit 5a3b372
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/support/select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def find_by_text(text)
end

def find_by_index(index)
options.select { |option| option.dom_attribute(:index) == index.to_s }
options.select { |option| option.property(:index) == index }
end

def find_by_value(value)
Expand Down
12 changes: 6 additions & 6 deletions rb/spec/unit/selenium/webdriver/support/select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ module Support
first_option = instance_double(Element, selected?: true)
second_option = instance_double(Element, selected?: false)

allow(first_option).to receive(:dom_attribute).with(:index).and_return '0'
allow(first_option).to receive(:property).with(:index).and_return 0
expect(first_option).not_to receive(:click)

allow(second_option).to receive(:dom_attribute).with(:index).and_return '1'
allow(second_option).to receive(:property).with(:index).and_return 1
expect(second_option).to receive(:click).once

allow(multi_select).to receive(:find_elements)
.with(tag_name: 'option')
.and_return([first_option, second_option])

Select.new(multi_select).select_by(:index, 1)
expect(first_option).to have_received(:dom_attribute).with(:index)
expect(second_option).to have_received(:dom_attribute).with(:index)
expect(first_option).to have_received(:property).with(:index)
expect(second_option).to have_received(:property).with(:index)
expect(multi_select).to have_received(:find_elements).with(tag_name: 'option')
end

Expand Down Expand Up @@ -198,8 +198,8 @@ module Support
.with(tag_name: 'option')
.and_return([first_option, second_option])

allow(first_option).to receive(:dom_attribute).with(:index).and_return('2')
allow(second_option).to receive(:dom_attribute).with(:index).and_return('1')
allow(first_option).to receive(:property).with(:index).and_return(2)
allow(second_option).to receive(:property).with(:index).and_return(1)

expect(first_option).to receive(:click).once
expect(second_option).not_to receive(:click)
Expand Down

0 comments on commit 5a3b372

Please sign in to comment.