From 6ded87429cbf676414eca2f744d966d5b47d2858 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Fri, 1 Sep 2023 11:32:45 -0500 Subject: [PATCH 1/4] [py] use property instead of atom to get index of option element --- py/selenium/webdriver/support/select.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/py/selenium/webdriver/support/select.py b/py/selenium/webdriver/support/select.py index 5b833124c1475..1834f7f8bf7b6 100644 --- a/py/selenium/webdriver/support/select.py +++ b/py/selenium/webdriver/support/select.py @@ -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}") @@ -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 @@ -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}") From 2f75bd2d01397d3ed63d289fd2077c47d0bd685b Mon Sep 17 00:00:00 2001 From: titusfortner Date: Fri, 1 Sep 2023 11:36:40 -0500 Subject: [PATCH 2/4] [dotnet] use property instead of atom to get the index of a Select Option --- dotnet/src/support/UI/SelectElement.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/src/support/UI/SelectElement.cs b/dotnet/src/support/UI/SelectElement.cs index 3d1b078acf3e2..41b46fa242998 100644 --- a/dotnet/src/support/UI/SelectElement.cs +++ b/dotnet/src/support/UI/SelectElement.cs @@ -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; @@ -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; From e2bece2e7f5cb0c2885aff92fb5004c5d310e51b Mon Sep 17 00:00:00 2001 From: titusfortner Date: Fri, 1 Sep 2023 11:39:21 -0500 Subject: [PATCH 3/4] [js] use property instead of atom to get index of option element --- javascript/node/selenium-webdriver/lib/select.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javascript/node/selenium-webdriver/lib/select.js b/javascript/node/selenium-webdriver/lib/select.js index fc99767541756..2bae64008323f 100644 --- a/javascript/node/selenium-webdriver/lib/select.js +++ b/javascript/node/selenium-webdriver/lib/select.js @@ -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) } } @@ -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() } From 90502a0337387c8978710ad036d316caa29aeffa Mon Sep 17 00:00:00 2001 From: titusfortner Date: Sat, 16 Sep 2023 23:00:31 -0500 Subject: [PATCH 4/4] [js] index needs to be a number not a string for this to pass --- javascript/node/selenium-webdriver/test/select_test.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/javascript/node/selenium-webdriver/test/select_test.js b/javascript/node/selenium-webdriver/test/select_test.js index 26733577cc9b6..7a04cc05f692a 100644 --- a/javascript/node/selenium-webdriver/test/select_test.js +++ b/javascript/node/selenium-webdriver/test/select_test.js @@ -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) } })