SeleniumHQ/selenium · error · ArgumentError

unexpected tag name #{tag_name.inspect}

Error message

unexpected tag name #{tag_name.inspect}

What it means

Support::Select.new asserts that the element's tag name equals 'select' (case-insensitive via casecmp). Support::Select only models HTML <select> elements, so passing any other element type (div, ul, input, option) is a programming error caught at construction. This prevents later method calls (options, select_all) from producing confusing failures.

Source

Thrown at rb/lib/selenium/webdriver/support/select.rb:31

# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

module Selenium
  module WebDriver
    module Support
      class Select
        #
        # @param [Element] element The select element to use
        #

        def initialize(element)
          tag_name = element.tag_name

          raise ArgumentError, "unexpected tag name #{tag_name.inspect}" unless tag_name.casecmp('select').zero?

          @element = element
          @multi = ![nil, 'false'].include?(element.dom_attribute(:multiple))
        end

        #
        # Does this select element support selecting multiple options?
        #
        # @return [Boolean]
        #

        def multiple?
          @multi
        end

        #
        # Get all options for this select element
        #

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Verify the element is actually a <select> via element.tag_name before constructing Select.
  2. Fix the locator/find to target the <select> element specifically.
  3. For custom (non-select) dropdowns, do not use Support::Select — interact with the elements directly via click.

Example fix

# before
el = driver.find_element(id: 'my-dropdown') # a <div>
select = Selenium::WebDriver::Support::Select.new(el)

# after
el = driver.find_element(tag_name: 'select')
select = Selenium::WebDriver::Support::Select.new(el)
Defensive patterns

Strategy: type-guard

Validate before calling

el = driver.find_element(id: 'my-select')
if el.tag_name.casecmp('select').zero?
  Selenium::WebDriver::Support::Select.new(el)
else
  raise "#{el.tag_name} is not a <select>; use direct clicks for custom dropdowns"
end

Type guard

def select_element?(el)
  el.respond_to?(:tag_name) && el.tag_name.casecmp('select').zero?
end

Try / catch

begin
  Selenium::WebDriver::Support::Select.new(el)
rescue ArgumentError => e
  raise unless e.message.include?('unexpected tag name')
  # handle custom dropdown with direct clicks
end

Prevention

When it happens

Trigger: Calling Selenium::WebDriver::Support::Select.new(element) where element.tag_name is anything other than 'select' — e.g. a <div> custom dropdown, a <ul>, an <option>, or a locator that matched the wrong element.

Common situations: Locating a custom (non-native) dropdown built with div/ul and wrapping it in Select; a flaky locator that occasionally matches a sibling element; migrating from a native select to a custom widget but keeping the Select wrapper.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/8f926c916a9d3639. Report an issue: GitHub.