Web DOM: A Complete Guide for QA Automation Engineers
๐–๐ก๐š๐ญ ๐ข๐ฌ ๐ญ๐ก๐ž ๐ƒ๐จ๐œ๐ฎ๐ฆ๐ž๐ง๐ญ ๐Ž๐›๐ฃ๐ž๐œ๐ญ ๐Œ๐จ๐๐ž๐ฅ (๐ƒ๐Ž๐Œ)?
The Document Object Model (DOM) is a programmatic representation of a web page (HTML). It allows developers to modify and update web pages using JavaScript, making them interactive.
This is what enables users to:
  • Click buttons
  • Fill forms
  • See dynamic content appear and disappear
โ„น๏ธ When a user interacts with a website, JavaScript updates the DOM behind the scenes to reflect those changes without refreshing the whole page.
๐’๐ข๐ฆ๐ฉ๐ฅ๐ž ๐ž๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž:
When a user clicks "Add to Cart" on an e-commerce site, the cart icon updates and a message appears. That's JavaScript updating the DOM to show those changes instantly.
๐‡๐จ๐ฐ ๐ญ๐จ ๐•๐ข๐ž๐ฐ ๐š๐ง๐ ๐ˆ๐ง๐ฌ๐ฉ๐ž๐œ๐ญ ๐ญ๐ก๐ž ๐ƒ๐Ž๐Œ
Opening the DOM Inspector
  1. Right-click anywhere on a webpage
  2. Select "Inspect"
  3. Look at the "Elements" tab content
๐”๐ง๐๐ž๐ซ๐ฌ๐ญ๐š๐ง๐๐ข๐ง๐  ๐ญ๐ก๐ž ๐ƒ๐Ž๐Œ ๐’๐ญ๐ซ๐ฎ๐œ๐ญ๐ฎ๐ซ๐ž
You'll see all the HTML elements organized in a tree structure:
  • Elements can be expanded or collapsed to view their contents
  • Each element has parent, child, and sibling relationships
  • The structure reflects the nesting of HTML tags
โ„น๏ธ When you right-click and inspect a specific element, the Elements tab automatically highlights that exact element in the tree.
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
๐ŸŸข ๐–๐ก๐š๐ญ ๐ข๐ฌ ๐ญ๐ก๐ž ๐ƒ๐Ž๐Œ ๐š๐ง๐ ๐–๐ก๐ฒ ๐’๐ก๐จ๐ฎ๐ฅ๐ ๐๐€ ๐„๐ง๐ ๐ข๐ง๐ž๐ž๐ซ๐ฌ ๐‚๐š๐ซ๐ž?
The Document Object Model (๐ƒ๐Ž๐Œ) is the bridge between a test automation code and the web pages you're testing.
Testing frameworks like Playwright rely on DOM manipulation to execute automated tests:
  • Element Location: Frameworks use CSS selectors and XPath to find elements in the DOM
  • Action Simulation: Clicks, text input, and navigation all happen through DOM interaction
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
๐ŸŸ  ๐“๐ก๐ž ๐๐€ ๐€๐ฎ๐ญ๐จ๐ฆ๐š๐ญ๐ข๐จ๐ง ๐–๐จ๐ซ๐ค๐Ÿ๐ฅ๐จ๐ฐ:
๐’๐ญ๐ž๐ฉ ๐Ÿ: Identify Target Elements
Open Developer Tools (F12) and inspect the elements you need to interact with:
โŸฉ Find unique identifiers (IDs, classes, attributes)
โŸฉ Identify selectors that won't break easily (avoid dynamic IDs or complex nested paths)
๐’๐ญ๐ž๐ฉ ๐Ÿ: Write a Test Code
Translate findings into a test automation code.
For example, to click a login button:
</>โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ</>
๐ฉ๐š๐ ๐ž.๐ฅ๐จ๐œ๐š๐ญ๐จ๐ซ(โ€˜๐›๐ฎ๐ญ๐ญ๐จ๐ง#๐ฅ๐จ๐ ๐ข๐งโ€™).๐œ๐ฅ๐ข๐œ๐ค()
</>โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ</>
This tells the framework: "Find the button element with ID 'login' in the DOM and click it."
๐’๐ญ๐ž๐ฉ ๐Ÿ‘: Framework Execution
Behind the scenes, the testing framework:
โŸฉ Uses JavaScript to interact with the DOM elements for the selector
โŸฉ Waits for the element to be ready (visible, enabled, etc.)
โŸฉ Performs the requested action by triggering DOM events
๐„๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž: ๐‹๐จ๐ ๐ข๐ง ๐…๐ฅ๐จ๐ฐ
The DOM looks like this:
</>โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ</>
<๐Ÿ๐จ๐ซ๐ฆ ๐œ๐ฅ๐š๐ฌ๐ฌ=โ€œ๐ฅ๐จ๐ ๐ข๐ง-๐Ÿ๐จ๐ซ๐ฆโ€>
โ € โ € <๐ข๐ง๐ฉ๐ฎ๐ญ ๐ข๐=โ€œ๐ฎ๐ฌ๐ž๐ซ๐ง๐š๐ฆ๐žโ€ ๐ญ๐ฒ๐ฉ๐ž=โ€œ๐ญ๐ž๐ฑ๐ญโ€ />
โ € โ € <๐ข๐ง๐ฉ๐ฎ๐ญ ๐ข๐=โ€œ๐ฉ๐š๐ฌ๐ฌ๐ฐ๐จ๐ซ๐โ€ ๐ญ๐ฒ๐ฉ๐ž=โ€œ๐ฉ๐š๐ฌ๐ฌ๐ฐ๐จ๐ซ๐โ€ />
โ € โ € <๐›๐ฎ๐ญ๐ญ๐จ๐ง ๐ข๐=โ€œ๐ฅ๐จ๐ ๐ข๐ง-๐›๐ญ๐งโ€>๐‹๐จ๐ ๐ข๐ง</๐›๐ฎ๐ญ๐ญ๐จ๐ง>
</๐Ÿ๐จ๐ซ๐ฆ>
</>โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ</>
Python Playwright Test Code for those elements would be:
</>โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ</>
๐ฉ๐š๐ ๐ž.๐ฅ๐จ๐œ๐š๐ญ๐จ๐ซ(โ€™#๐ฎ๐ฌ๐ž๐ซ๐ง๐š๐ฆ๐žโ€™).๐Ÿ๐ข๐ฅ๐ฅ(โ€˜๐ญ๐ž๐ฌ๐ญ๐ฎ๐ฌ๐ž๐ซ@๐ž๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž.๐œ๐จ๐ฆโ€™)
๐ฉ๐š๐ ๐ž.๐ฅ๐จ๐œ๐š๐ญ๐จ๐ซ(โ€™#๐ฉ๐š๐ฌ๐ฌ๐ฐ๐จ๐ซ๐โ€™).๐Ÿ๐ข๐ฅ๐ฅ(โ€˜๐’๐ž๐œ๐ฎ๐ซ๐ž๐๐š๐ฌ๐ฌ๐Ÿ๐Ÿ๐Ÿ‘โ€™)
๐ฉ๐š๐ ๐ž.๐ฅ๐จ๐œ๐š๐ญ๐จ๐ซ(โ€™#๐ฅ๐จ๐ ๐ข๐ง-๐›๐ญ๐งโ€™).๐œ๐ฅ๐ข๐œ๐ค()
</>โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ</>
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
๐ŸŸฃ ๐๐ซ๐จ ๐“๐ข๐ฉ ๐Ÿ๐จ๐ซ ๐๐€ ๐€๐ฎ๐ญ๐จ๐ฆ๐š๐ญ๐ข๐จ๐ง ๐„๐ง๐ ๐ข๐ง๐ž๐ž๐ซ๐ฌ
Before writing test code, verify a selector works in the Browser Console (Developer Tools).
Open the Console and type:
</>โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ</>
๐๐จ๐œ๐ฎ๐ฆ๐ž๐ง๐ญ.๐ช๐ฎ๐ž๐ซ๐ฒ๐’๐ž๐ฅ๐ž๐œ๐ญ๐จ๐ซ(โ€˜๐›๐ฎ๐ญ๐ญ๐จ๐ง#๐ฅ๐จ๐ ๐ข๐ง-๐›๐ญ๐งโ€™)
</>โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ</>
If it finds the element, the selector is good to be used in the test.
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
๐“๐š๐ค๐ž๐š๐ฐ๐š๐ฒ:
โœ… The DOM is a programmatic representation of HTML
โœ… Testing frameworks use the DOM to find and interact with elements
โœ… "Elements" tab in Developer Tools allows to inspect and understand DOM structure
๐.๐’. ๐Ÿšฉ ๐ˆ๐Ÿ ๐ฒ๐จ๐ฎ ๐ก๐š๐ฏ๐ž๐งโ€™๐ญ ๐ฐ๐š๐ญ๐œ๐ก๐ž๐ ๐ข๐ญ ๐ฒ๐ž๐ญ, ๐ฒ๐จ๐ฎ๐ซ ๐ง๐ž๐ฑ๐ญ ๐ฌ๐ญ๐ž๐ฉ ๐ข๐ฌ ๐ญ๐ก๐ž ๐…๐‘๐„๐„ ๐Ÿ‘-๐ฉ๐š๐ซ๐ญ โ€œ๐Œ๐š๐ง๐ฎ๐š๐ฅ ๐๐€ โ†’ ๐’๐ƒ๐„๐“โ€ ๐ฐ๐จ๐ซ๐ค๐ฌ๐ก๐จ๐ฉ,ย ๐š ๐ฌ๐ก๐จ๐ซ๐ญ ๐ฆ๐ข๐ง๐ข-๐œ๐จ๐ฎ๐ซ๐ฌ๐ž ๐ญ๐ก๐š๐ญ ๐ ๐ข๐ฏ๐ž๐ฌ ๐ฒ๐จ๐ฎ ๐ญ๐ก๐ž ๐Ÿ๐ฎ๐ฅ๐ฅ ๐ซ๐จ๐š๐๐ฆ๐š๐ฉ ๐ญ๐จ ๐›๐ž๐œ๐จ๐ฆ๐ข๐ง๐  ๐š ๐ฆ๐ข๐-๐ฅ๐ž๐ฏ๐ž๐ฅ ๐’๐ƒ๐„๐“ ๐š๐ง๐ ๐ฉ๐š๐ฌ๐ฌ๐ข๐ง๐  ๐ข๐ง๐ญ๐ž๐ซ๐ฏ๐ข๐ž๐ฐ๐ฌ.
13
2 comments
Matviy Cherniavski
6
Web DOM: A Complete Guide for QA Automation Engineers
QA Automation Accelerator
skool.com/qa-automation-career-hub
Become a job-ready QA Automation Engineer/SDET in 3โ€“4 months. AI-powered prep, real SaaS project, Certificate of Completion, and live support. ๐Ÿš€
Powered by