Skip to content

Commit c9d58a8

Browse files
committed
No need to check for multiple values when selecting/deselecting by index, as the index is unique
1 parent d3850f8 commit c9d58a8

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

lib/WebDriverSelect.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,17 @@ public function getFirstSelectedOption()
9797
*/
9898
public function selectByIndex($index)
9999
{
100-
$matched = false;
101100
foreach ($this->getOptions() as $option) {
102101
if ($option->getAttribute('index') === (string) $index) {
103102
if (!$option->isSelected()) {
104103
$option->click();
105-
if (!$this->isMultiple()) {
106-
return;
107-
}
108104
}
109-
$matched = true;
105+
106+
return;
110107
}
111108
}
112-
if (!$matched) {
113-
throw new NoSuchElementException(
114-
sprintf('Cannot locate option with index: %d', $index)
115-
);
116-
}
109+
110+
throw new NoSuchElementException(sprintf('Cannot locate option with index: %d', $index));
117111
}
118112

119113
/**
@@ -262,8 +256,12 @@ public function deselectByIndex($index)
262256
}
263257

264258
foreach ($this->getOptions() as $option) {
265-
if ($option->getAttribute('index') === (string) $index && $option->isSelected()) {
266-
$option->click();
259+
if ($option->getAttribute('index') === (string) $index) {
260+
if ($option->isSelected()) {
261+
$option->click();
262+
}
263+
264+
return;
267265
}
268266
}
269267
}

0 commit comments

Comments
 (0)