Skip to content

[🚀 Feature]: Unifying Select Class Across All Bindings #15265

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

Open
1 of 5 tasks
shbenzer opened this issue Feb 10, 2025 · 3 comments · May be fixed by Merrn60/selenium-select-visibility-test#1 or #15694
Open
1 of 5 tasks

[🚀 Feature]: Unifying Select Class Across All Bindings #15265

shbenzer opened this issue Feb 10, 2025 · 3 comments · May be fixed by Merrn60/selenium-select-visibility-test#1 or #15694
Labels
C-dotnet .NET Bindings C-java Java Bindings C-rb Ruby Bindings good first issue Good first issue for new contributors to start with I-enhancement Something could be better

Comments

@shbenzer
Copy link
Contributor

shbenzer commented Feb 10, 2025

Feature and motivation

User @FFederi noticed that the Select class is not consistent across language bindings in #15135.

I'm creating this ticket so we can discuss and track making this consistent

Usage example

In Java:

selectByVisibleText() and selectByContainsVisibleText() should both check properties "visibility", "display", and "opacity", for values of "hidden", "none", "0", "0.0".

Tracking

@shbenzer shbenzer added I-enhancement Something could be better A-needs-triaging A Selenium member will evaluate this soon! labels Feb 10, 2025
Copy link

@shbenzer, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@shbenzer shbenzer added A-needs decision TLC needs to discuss and agree A-needs investigation TLC needs to do discovery labels Feb 10, 2025
@shbenzer shbenzer added C-rb Ruby Bindings C-dotnet .NET Bindings C-java Java Bindings good first issue Good first issue for new contributors to start with and removed A-needs decision TLC needs to discuss and agree A-needs investigation TLC needs to do discovery A-needs-triaging A Selenium member will evaluate this soon! labels Apr 11, 2025
@Merrn60
Copy link

Merrn60 commented May 2, 2025

I've created a small test with Java and HTML to demonstrate the visibility issue.

The test checks if selectByVisibleText() skips options hidden using CSS (display: none, visibility: hidden, opacity: 0).
Below is my test code that shows the issue. I hope it can help in fixing the problem.


`

<style> #hiddenDisplay { display: none; } #hiddenVisibility { visibility: hidden; } #hiddenOpacity { opacity: 0; } </style> Visible Option Hidden Option (display:none) Hidden Option (visibility:hidden) Hidden Option (opacity:0) `

java code

`package org.example;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.Select;
import java.util.List;
import java.util.Scanner;

public class SelectHiddenOptionsTest {
public static void main(String[] args) {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
WebDriver driver = new ChromeDriver(options);
try {
driver.get("file:///C:/Users/dell/OneDrive/Desktop/test_select.html");
WebElement selectElement = driver.findElement(By.id("mySelect"));
Select select = new Select(selectElement);

        // Run test cases
        testOption(select, "Visible Option", true);
        testOption(select, "Hidden Option (display:none)", false);
        testOption(select, "Hidden Option (visibility:hidden)", false);
        testOption(select, "Hidden Option (opacity:0)", false);

        System.out.println("✅ Test execution completed. Press Enter to close the browser...");
        new Scanner(System.in).nextLine();
    } finally {
        driver.quit();
    }
}

private static void testOption(Select select, String visibleText, boolean shouldSucceed) {
    try {
        WebElement option = findOptionByText(select, visibleText);
        if (option != null && isVisible(option)) {
            select.selectByVisibleText(visibleText);
            if (shouldSucceed) {
                System.out.println("✅ PASSED: Successfully selected: " + visibleText);
            } else {
                System.out.println("❌ FAILED: Should NOT have been able to select: " + visibleText);
            }
        } else {
            if (shouldSucceed) {
                System.out.println("❌ FAILED: Could NOT select: " + visibleText + " (option not visible)");
            } else {
                System.out.println("✅ PASSED: Correctly failed to select: " + visibleText + " (option not visible)");
            }
        }
    } catch (NoSuchElementException e) {
        if (shouldSucceed) {
            System.out.println("❌ FAILED: Could NOT select: " + visibleText + " → " + e.getMessage());
        } else {
            System.out.println("✅ PASSED: Correctly failed to select: " + visibleText + " → " + e.getMessage());
        }
    } catch (Exception e) {
        System.out.println("⚠️ ERROR: Unexpected error while selecting: " + visibleText + " → " + e.getMessage());
    }
}

private static WebElement findOptionByText(Select select, String text) {
    List<WebElement> options = select.getOptions();
    for (WebElement option : options) {
        if (text.equals(option.getText())) {
            return option;
        }
    }
    return null;
}

private static boolean isVisible(WebElement element) {
    try {
        String visibility = element.getCssValue("visibility");
        String display = element.getCssValue("display");
        String opacity = element.getCssValue("opacity");
        return !visibility.equals("hidden") && !display.equals("none") && !opacity.equals("0") && !opacity.equals("0.0");
    } catch (Exception e) {
        return false;
    }
}

}
`

@Merrn60
Copy link

Merrn60 commented May 2, 2025

Based on my test, selectByVisibleText() currently selects hidden options, which contradicts the expectation that it should only interact with visible elements. I propose that the Select class across all bindings (Java, Python, Ruby, etc.) standardizes visibility checks using logic similar to my isVisible method, ensuring display: none, visibility: hidden, and opacity: 0 are consistently respected. Has anyone tested this behavior in Python or .NET bindings to compare?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-dotnet .NET Bindings C-java Java Bindings C-rb Ruby Bindings good first issue Good first issue for new contributors to start with I-enhancement Something could be better
Projects
None yet
2 participants