Software Development

How do I fix the "Element should have been select but was input" error in Selenium WebDriver?

DE Asked by Derek Thompson · 14-07-2025
0 upvotes 13,883 views 0 comments
The question

I am attempting to automate a dropdown menu on a registration page using the Selenium Select class in Java. However, every time my script runs, it throws an UnexpectedTagNameException stating that the element should have been "select" but was "input". I’ve checked my locator and it seems to be pointing to the right area, but I can't figure out why the Select class is rejecting it. Is this because the dropdown is a custom Bootstrap or React component rather than a standard HTML tag?

3 answers

0
AN
Answered on 17-07-2025

The error occurs because the Selenium Select class is strictly designed to work only with HTML <select> tags. If your web application uses a modern UI framework like Angular, React, or Bootstrap, the "dropdown" is likely a styled <div> or <input> tag that mimics a dropdown's behavior. To interact with these, you cannot use the Select class. Instead, you must use standard WebElement clicks. First, click the element to open the options list, then locate the specific option (often an <li> or a <span>) and click it. You may also need to use WebDriverWait to ensure the list is visible before clicking the choice.

0
MA
Answered on 20-07-2025

Could you share the HTML snippet of the element you are trying to target, and have you checked if there is a hidden <select> tag nearby that the <input> is merely controlling? Sometimes developers hide the real select element for styling purposes, and you might need to use JavaScriptExecutor to make it visible or interact with it directly to get the Select class to work without throwing that specific exception.

PA 22-07-2025

Marcus, I've seen that "hidden select" trick often in older jQuery plugins. If that's the case for Derek, he could try using ((JavascriptExecutor)driver).executeScript("arguments[0].style.display='block';", hiddenSelectElement); before initializing the Select object. However, if it's a truly custom component with no select tag at all, then Angela's suggestion of clicking through the divs is the only reliable way to handle the interaction.

0
SA
Answered on 25-07-2025

This usually happens with "Autocomplete" fields. They look like dropdowns but are technically text inputs. Just use sendKeys() followed by an arrow key or Enter.

DE 27-07-2025

I agree with Sarah. Many modern "dropdowns" are actually searchable inputs. If you type the first few letters and then use the Keys.ARROW_DOWN and Keys.ENTER commands, it's often much faster than trying to locate a specific dynamic list item.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session