From a96c86d34e24c5ff5a50ea702fa3b34a227c568b Mon Sep 17 00:00:00 2001 From: Viktoriia Ivanova Date: Tue, 19 Aug 2025 14:45:16 -0700 Subject: [PATCH 1/4] Updated Java Language Level to the JDK_17 for IntelliJ IDEA --- .idea/misc.xml | 4 ++-- java/java.iml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index c052579f90a0f..cc07094bea576 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + - \ No newline at end of file + diff --git a/java/java.iml b/java/java.iml index dcdaca645e3e4..7a0e4e1870133 100644 --- a/java/java.iml +++ b/java/java.iml @@ -3,7 +3,7 @@ - + From 12d83f0f28ed49dc08705e200474ebf72f2425e6 Mon Sep 17 00:00:00 2001 From: Viktoriia Ivanova Date: Wed, 20 Aug 2025 12:08:29 -0700 Subject: [PATCH 2/4] [java] Fix select being able to select options hidden by css rules Fixes #15265 --- .../openqa/selenium/support/ui/Select.java | 5 +++++ .../support/ui/SelectElementTest.java | 22 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/java/src/org/openqa/selenium/support/ui/Select.java b/java/src/org/openqa/selenium/support/ui/Select.java index 264585e5417f6..9942b7057832e 100644 --- a/java/src/org/openqa/selenium/support/ui/Select.java +++ b/java/src/org/openqa/selenium/support/ui/Select.java @@ -123,6 +123,7 @@ public WebElement getFirstSelectedOption() { @Override public void selectByVisibleText(String text) { assertSelectIsEnabled(); + assertSelectIsVisible(); // try to find the option via XPATH ... List options = @@ -130,6 +131,8 @@ public void selectByVisibleText(String text) { By.xpath(".//option[normalize-space(.) = " + Quotes.escape(text) + "]")); for (WebElement option : options) { + if (!hasCssPropertyAndVisible(option)) + throw new NoSuchElementException("Invisible option with text: " + text); setSelected(option, true); if (!isMultiple()) { return; @@ -154,6 +157,8 @@ public void selectByVisibleText(String text) { for (WebElement option : candidates) { if (trimmed.equals(option.getText().trim())) { + if (!hasCssPropertyAndVisible(option)) + throw new NoSuchElementException("Invisible option with text: " + text); setSelected(option, true); if (!isMultiple()) { return; diff --git a/java/test/org/openqa/selenium/support/ui/SelectElementTest.java b/java/test/org/openqa/selenium/support/ui/SelectElementTest.java index 0587b630b3261..8c81613514b81 100644 --- a/java/test/org/openqa/selenium/support/ui/SelectElementTest.java +++ b/java/test/org/openqa/selenium/support/ui/SelectElementTest.java @@ -29,6 +29,9 @@ import org.openqa.selenium.testing.Ignore; import org.openqa.selenium.testing.JupiterTestBase; +import java.util.Arrays; +import java.util.List; + class SelectElementTest extends JupiterTestBase { @BeforeEach @@ -176,8 +179,11 @@ void shouldNotAllowInvisibleOptionsToBeSelectedByContainsVisibleText() { WebElement selectElement = driver.findElement(By.id("invisible_multi_select")); Select select = new Select(selectElement); - assertThatExceptionOfType(NoSuchElementException.class) - .isThrownBy(() -> select.selectByContainsVisibleText("Apples")); + List options = Arrays.asList("Apples", "Pears", "Oranges", "Lemons"); + options.forEach( + option -> + assertThatExceptionOfType(NoSuchElementException.class) + .isThrownBy(() -> select.selectByVisibleText(option))); } @Test @@ -198,6 +204,18 @@ void shouldThrowExceptionOnSelectByVisibleTextIfOptionDisabled() { .isThrownBy(() -> select.selectByVisibleText("Disabled")); } + @Test + void shouldThrowExceptionOnSelectByVisibleTextIfOptionHidden() { + WebElement selectElement = driver.findElement(By.id("invisible_multi_select")); + Select select = new Select(selectElement); + + List options = Arrays.asList("Apples", "Pears", "Oranges", "Lemons"); + options.forEach( + option -> + assertThatExceptionOfType(NoSuchElementException.class) + .isThrownBy(() -> select.selectByVisibleText(option))); + } + @Test void shouldAllowOptionsToBeSelectedByIndex() { WebElement selectElement = driver.findElement(By.name("select_empty_multiple")); From 737d42074ca1db389d730057d0d1d2e355eac1d6 Mon Sep 17 00:00:00 2001 From: Viktoriia Ivanova Date: Wed, 20 Aug 2025 14:20:32 -0700 Subject: [PATCH 3/4] [java] Formatted with ./scripts/format.sh --- .../openqa/selenium/support/ui/SelectElementTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/java/test/org/openqa/selenium/support/ui/SelectElementTest.java b/java/test/org/openqa/selenium/support/ui/SelectElementTest.java index 8c81613514b81..729f902b753e8 100644 --- a/java/test/org/openqa/selenium/support/ui/SelectElementTest.java +++ b/java/test/org/openqa/selenium/support/ui/SelectElementTest.java @@ -21,6 +21,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.openqa.selenium.testing.drivers.Browser.ALL; +import java.util.Arrays; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; @@ -29,9 +31,6 @@ import org.openqa.selenium.testing.Ignore; import org.openqa.selenium.testing.JupiterTestBase; -import java.util.Arrays; -import java.util.List; - class SelectElementTest extends JupiterTestBase { @BeforeEach @@ -181,9 +180,9 @@ void shouldNotAllowInvisibleOptionsToBeSelectedByContainsVisibleText() { List options = Arrays.asList("Apples", "Pears", "Oranges", "Lemons"); options.forEach( - option -> - assertThatExceptionOfType(NoSuchElementException.class) - .isThrownBy(() -> select.selectByVisibleText(option))); + option -> + assertThatExceptionOfType(NoSuchElementException.class) + .isThrownBy(() -> select.selectByVisibleText(option))); } @Test From 5d54e753ecff9ab32c4a38117ba76a37d620deb7 Mon Sep 17 00:00:00 2001 From: Viktoriia Ivanova Date: Wed, 20 Aug 2025 15:00:43 -0700 Subject: [PATCH 4/4] [java] Change the JDK setting for IntelliJ back to JDK 11 --- .idea/misc.xml | 2 +- java/java.iml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index cc07094bea576..43262c34163c2 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + diff --git a/java/java.iml b/java/java.iml index 7a0e4e1870133..dcdaca645e3e4 100644 --- a/java/java.iml +++ b/java/java.iml @@ -3,7 +3,7 @@ - +