Skip to content

Commit

Permalink
use attribute endpoint to evaluate multiple selects
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Mar 3, 2021
1 parent 7274f48 commit 9b6231a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion java/client/src/org/openqa/selenium/support/ui/Select.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Select(WebElement element) {

this.element = element;

String value = element.getAttribute("multiple");
String value = element.getDomAttribute("multiple");

// The atoms normalize the returned value, but check for "false"
isMulti = (value != null && !"false".equals(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void shouldNotIndicateThatANormalSelectSupportsMultipleOptions() {
private WebElement mockSelectWebElement(String multiple) {
final WebElement element = mock(WebElement.class);
when(element.getTagName()).thenReturn("select");
when(element.getAttribute("multiple")).thenReturn(multiple);
when(element.getDomAttribute("multiple")).thenReturn(multiple);
return element;
}

Expand Down Expand Up @@ -249,7 +249,7 @@ public void shouldFallBackToSlowLooksUpsWhenGetByVisibleTextFailsAndThereIsASpac

final WebElement element = mockSelectWebElement("multiple");
when(element.getTagName()).thenReturn("select");
when(element.getAttribute("multiple")).thenReturn("false");
when(element.getDomAttribute("multiple")).thenReturn("false");
when(element.findElements(xpath1)).thenReturn(emptyList());
when(element.findElements(xpath2)).thenReturn(Collections.singletonList(firstOption));
when(firstOption.getText()).thenReturn("foo bar");
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/support/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, webelement):
"Select only works on <select> elements, not on <%s>" %
webelement.tag_name)
self._el = webelement
multi = self._el.get_attribute("multiple")
multi = self._el.get_dom_attribute("multiple")
self.is_multiple = multi and multi != "false"

@property
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/support/select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize(element)
raise ArgumentError, "unexpected tag name #{tag_name.inspect}" unless tag_name.casecmp('select').zero?

@element = element
@multi = ![nil, 'false'].include?(element.attribute(:multiple))
@multi = ![nil, 'false'].include?(element.dom_attribute(:multiple))
end

#
Expand Down Expand Up @@ -258,7 +258,7 @@ def find_by_text(text)
end

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

def find_by_value(value)
Expand Down
24 changes: 12 additions & 12 deletions rb/spec/unit/selenium/webdriver/support/select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ module Support
describe Select do
let(:select) do
select_element = instance_double(Element, tag_name: 'select')
allow(select_element).to receive(:attribute).with(:multiple)
allow(select_element).to receive(:dom_attribute).with(:multiple)
select_element
end

let(:multi_select) do
select_element = instance_double(Element, tag_name: 'select')
allow(select_element).to receive(:attribute).with(:multiple).and_return 'multiple'
allow(select_element).to receive(:dom_attribute).with(:multiple).and_return 'multiple'
select_element
end

Expand All @@ -46,10 +46,10 @@ module Support
it 'indicates whether a select is multiple correctly' do
selects = Array.new(4) { instance_double(Element, tag_name: 'select') }

allow(selects[0]).to receive(:attribute).with(:multiple).and_return('false')
allow(selects[1]).to receive(:attribute).with(:multiple).and_return(nil)
allow(selects[2]).to receive(:attribute).with(:multiple).and_return('true')
allow(selects[3]).to receive(:attribute).with(:multiple).and_return('multiple')
allow(selects[0]).to receive(:dom_attribute).with(:multiple).and_return('false')
allow(selects[1]).to receive(:dom_attribute).with(:multiple).and_return(nil)
allow(selects[2]).to receive(:dom_attribute).with(:multiple).and_return('true')
allow(selects[3]).to receive(:dom_attribute).with(:multiple).and_return('multiple')

expect(Select.new(selects[0])).not_to be_multiple
expect(Select.new(selects[1])).not_to be_multiple
Expand Down 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(:attribute).with(:index).and_return '0'
allow(first_option).to receive(:dom_attribute).with(:index).and_return '0'
expect(first_option).not_to receive(:click)

allow(second_option).to receive(:attribute).with(:index).and_return '1'
allow(second_option).to receive(:dom_attribute).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(:attribute).with(:index)
expect(second_option).to have_received(:attribute).with(:index)
expect(first_option).to have_received(:dom_attribute).with(:index)
expect(second_option).to have_received(:dom_attribute).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(:attribute).with(:index).and_return('2')
allow(second_option).to receive(:attribute).with(:index).and_return('1')
allow(first_option).to receive(:dom_attribute).with(:index).and_return('2')
allow(second_option).to receive(:dom_attribute).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 9b6231a

Please sign in to comment.