Skip to content

Commit 86b787c

Browse files
committed
[py] use property instead of atom to get index of option element
1 parent 57503a5 commit 86b787c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

py/selenium/webdriver/support/select.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,15 @@ def select_by_value(self, value: str) -> None:
8585

8686
def select_by_index(self, index: int) -> None:
8787
"""Select the option at the given index. This is done by examining the
88-
"index" attribute of an element, and not merely by counting.
88+
"index" property of an element, and not merely by counting.
8989
9090
:Args:
9191
- index - The option at this index will be selected
9292
9393
throws NoSuchElementException If there is no option with specified index in SELECT
9494
"""
95-
match = str(index)
9695
for opt in self.options:
97-
if opt.get_attribute("index") == match:
96+
if opt.get_property("index") == index:
9897
self._set_selected(opt)
9998
return
10099
raise NoSuchElementException(f"Could not locate element with index {index}")
@@ -172,7 +171,7 @@ def deselect_by_value(self, value: str) -> None:
172171

173172
def deselect_by_index(self, index: int) -> None:
174173
"""Deselect the option at the given index. This is done by examining
175-
the "index" attribute of an element, and not merely by counting.
174+
the "index" property of an element, and not merely by counting.
176175
177176
:Args:
178177
- index - The option at this index will be deselected
@@ -182,7 +181,7 @@ def deselect_by_index(self, index: int) -> None:
182181
if not self.is_multiple:
183182
raise NotImplementedError("You may only deselect options of a multi-select")
184183
for opt in self.options:
185-
if opt.get_attribute("index") == str(index):
184+
if opt.get_property("index") == index:
186185
self._unset_selected(opt)
187186
return
188187
raise NoSuchElementException(f"Could not locate element with index {index}")

0 commit comments

Comments
 (0)