Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[πŸš€ Feature]: Allow compound class name locators when finding elementsΒ #16292

@cgoldberg

Description

@cgoldberg

Description

I think we should allow finding elements by class name in all bindings when the class attribute on an element contains multiple classes (i.e: class="a b c").

Currently, if you try to find an element using a class name containing whitespace, the client code rejects it with a "Compound classes not allowed" exception.

From a webdriver's perspective, there is really no such thing as finding an element by "class name". It's just a convenience that gets translated to a CSS selector before requesting it from the webdriver. So finding an element by class name foo really just tries to find it using CSS selector .foo.

In the case of compound class names, we could convert the whitespace to dots. If a user called a method to find an element with By.CLASS_NAME values of a b c or a b c, instead of rejecting it, we could convert it to CSS selector .a.b.c (similar to how we already convert non-compound class names). This would then allow compound class names to be used.

This is a very common issue that comes up with using Selenium. The answer is usually "Don't use compound class names, convert it to a CSS selector instead".

I raised this issue in a Slack conversation, and the only reasoning I got for the current behavior had to do with old browsers not supporting it and the way it was initially implemented before there was an API for CSS selectors.

Have you considered any alternatives or workarounds?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!I-enhancementSomething could be better

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions