Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Jonathan GrieveTreehouse Moderator 90,956 Points
Is it ever okay to locate by ID's?
I just wanted to be clear on something.
I understand it's bad practice to create an ID element simply so we can grab it using Selenium, but is it ever okay to select an element with a prexisting id like Craig did?
It seems a shame not to be able to use the method if we know we can :)
Steven Parker220,634 Points
I wouldn't agree that it's always bad practice to use ID's. I think it's entirely appropriate if you know there will only ever be one item on the page that serves a particular purpose.
I believe the general rule about using classes instead of ID is intended primarily for styling, though even there it might still be appropriate if you're certain that only one element will ever receive a particular style.
Craig DennisTreehouse Teacher
Yeah by all means if the ID exists use it, but don't go making them yourself ;)