Have you failed a job interview?
Send us your job interview questions and get correct answers.

BP31: Locate elements and controls using the right method

Use the following order: id > name > css > xpath

Id

There can be only one id on the page. Finding element by id is very fast and efficient. There is a low risk that the test would get broken because the author of the page has changed the id. Such things don't happen often. 

Name

There can be multiple controls with the same name. But it doesn't happen often. Finding element by name is very fast and efficient. There is a low risk hat the test would get broken because the author of the page has changed the name attribute of the control. Such things don't happen often as the programmers are using names in their code and if they change their front-end code, they would need to change back-end code as well.

CSS

Finding element by the css selector is fine until the author of the page changes style, template or slightly tweaks html code of the page. Such change is more likely than the change of id or name attribute.

XPath

XPath is fine, but it's complex and hard to read for junior testers. It can also be very fragile when more complex xpath query is used.

Comments

No Comments Yet.
Be the first to tell us what you think.

Download Better Coder application to your phone and get unlimited access to the collection of enterprise best practices.

Get it on Google Play