You see a login page: a logo, two boxes, a button.
The browser sees a tree of elements. Automation talks to that tree — the DOM — not to the pixels.
Every web page is written in HTML: nested tags that the browser turns into a live tree called the DOM (Document Object Model). When Selenium "clicks a button", it finds a node in this tree and fires a click on it. To automate a page, you must be able to read its tree.
<form id="login-form"> <input type="text" id="user-name" class="input_error form_input" placeholder="Username"> <input type="password" id="password" class="form_input" placeholder="Password"> <input type="submit" id="login-button" value="Login"> </form>
Read one line: the tag (input) says what kind of element it is; attributes (id, class, type, placeholder) describe it. Two attributes matter most for testers:
id — meant to be unique on the page. The gold standard for locating.class — styling labels, often shared by many elements (note one element can have several, space-separated).Open saucedemo.com (our practice app for the whole course). Press F12, or right-click the username box → Inspect. The Elements panel shows the DOM with your element highlighted — this is exactly the HTML above, live. Hover nodes in the panel and watch the page highlight; click the arrows to unfold the tree.
▼ <div class="form_group">
<input class="input_error form_input" placeholder="Username"
type="text" data-test="username" id="user-name" name="user-name">
</div>
images/devtools-inspect.pngNotice data-test="username" — a test attribute the developers added specifically for automation. When your team's app has these, always prefer them: they never change for styling reasons. Asking developers to add them is a professional move, not a weakness.
On saucedemo.com with DevTools open, inspect and write down the tag, id (if any), and classes of:
Bonus: which of the five has a data-test attribute? (Answer: nearly all — saucedemo is automation-friendly.)