Skip to content

use property instead of atom to get index of option element #12662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dotnet/src/support/UI/SelectElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void SelectByIndex(int index)

foreach (IWebElement option in this.Options)
{
if (option.GetAttribute("index") == match)
if (option.GetDomProperty("index") == match)
{
SetSelected(option, true);
return;
Expand Down Expand Up @@ -364,7 +364,7 @@ public void DeselectByIndex(int index)
string match = index.ToString(CultureInfo.InvariantCulture);
foreach (IWebElement option in this.Options)
{
if (match == option.GetAttribute("index"))
if (match == option.GetDomProperty("index"))
{
SetSelected(option, false);
return;
Expand Down
4 changes: 2 additions & 2 deletions javascript/node/selenium-webdriver/lib/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Select {
}

for (let option of options) {
if ((await option.getAttribute('index')) === index.toString()) {
if ((await option.getProperty('index')) === index) {
await this.setSelected(option)
}
}
Expand Down Expand Up @@ -415,7 +415,7 @@ class Select {
}

for (let option of options) {
if ((await option.getAttribute('index')) === index.toString()) {
if ((await option.getProperty('index')) === index) {
if (await option.isSelected()) {
await option.click()
}
Expand Down
9 changes: 3 additions & 6 deletions javascript/node/selenium-webdriver/test/select_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,10 @@ suite(
let selector = new Select(
driver.findElement(By.name(singleSelectValues1['name']))
)
for (let x in singleSelectValues1['values']) {
await selector.selectByIndex(x)
for (let [index, value] of singleSelectValues1['values'].entries()) {
await selector.selectByIndex(index)
let ele = await selector.getFirstSelectedOption()
assert.deepEqual(
await ele.getText(),
singleSelectValues1['values'][x]
)
assert.deepEqual(await ele.getText(), value)
}
})

Expand Down
9 changes: 4 additions & 5 deletions py/selenium/webdriver/support/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,15 @@ def select_by_value(self, value: str) -> None:

def select_by_index(self, index: int) -> None:
"""Select the option at the given index. This is done by examining the
"index" attribute of an element, and not merely by counting.
"index" property of an element, and not merely by counting.

:Args:
- index - The option at this index will be selected

throws NoSuchElementException If there is no option with specified index in SELECT
"""
match = str(index)
for opt in self.options:
if opt.get_attribute("index") == match:
if opt.get_property("index") == index:
self._set_selected(opt)
return
raise NoSuchElementException(f"Could not locate element with index {index}")
Expand Down Expand Up @@ -172,7 +171,7 @@ def deselect_by_value(self, value: str) -> None:

def deselect_by_index(self, index: int) -> None:
"""Deselect the option at the given index. This is done by examining
the "index" attribute of an element, and not merely by counting.
the "index" property of an element, and not merely by counting.

:Args:
- index - The option at this index will be deselected
Expand All @@ -182,7 +181,7 @@ def deselect_by_index(self, index: int) -> None:
if not self.is_multiple:
raise NotImplementedError("You may only deselect options of a multi-select")
for opt in self.options:
if opt.get_attribute("index") == str(index):
if opt.get_property("index") == index:
self._unset_selected(opt)
return
raise NoSuchElementException(f"Could not locate element with index {index}")
Expand Down