What differs #name
from .name
in CSS? How can this help me in testing?
Asked
Active
Viewed 231 times
-2

Koby Douek
- 16,156
- 19
- 74
- 103

Vasyl
- 13
- 3
-
"How can this help me in testing?" It doesn't offer any benefits unique to testing. A selector is a selector. You could, in theory, use attribute selectors instead of class or ID selectors, or you could just use class and ID selectors like you would in a stylesheet and they'll just work (assuming they're implemented correctly). That's the idea behind using CSS selectors: they just work. – BoltClock Jul 10 '17 at 10:29
1 Answers
0
The CSS #
selector is for selecting which elements will be styled according to the element's ID, while the .
CSS selector is for selecting which elements will be styled according to the element's class name.
So, using #name
will select only an element with id='name'
, and using .name
will select all elements with class='name'
.
Regarding your question: How can this help me in testing?
Using CSS selectors have nothing to do with testing. It has to do with selecting which elements to style according to their ID or class attributes.

Koby Douek
- 16,156
- 19
- 74
- 103
-
"Using CSS selectors have nothing to do with testing." Just because you are not aware of the numerous QA tools that match elements using CSS selectors doesn't mean that they have nothing to do with testing. CSS selectors have many uses - styling elements is just *one* of them. Additionally, since you specifically call out styling elements as the "only" use, it should be noted that ID selectors are not guaranteed to match only exactly one element even in a CSS context. – BoltClock Jul 10 '17 at 10:27