Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonathan Grieve
Treehouse Moderator 91,253 PointsIs 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 :)
2 Answers
Steven Parker
231,248 PointsI 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 Dennis
Treehouse TeacherYeah by all means if the ID exists use it, but don't go making them yourself ;)