{"id":13289,"date":"2022-09-28T16:32:01","date_gmt":"2022-09-28T11:02:01","guid":{"rendered":"https:\/\/blog.guvi.in\/?p=13289"},"modified":"2025-10-07T12:11:21","modified_gmt":"2025-10-07T06:41:21","slug":"what-is-dom-in-selenium","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/what-is-dom-in-selenium\/","title":{"rendered":"How to Master DOM in Selenium for Beginners"},"content":{"rendered":"\n<p>DOM stands for \u2018Document Object Model\u2019. In simple words, the DOM is used by web developers to make changes in the document structure, style, and content of a web page. Thus, DOM in Selenium WebDriver is considered as an important component in web development using HTML5 &amp; JavaScript.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is DOM and Its Importance In Web Development?<\/strong><\/h2>\n\n\n\n<p>DOM defines a standard for accessing documents. Technically, DOM is an application programming interface(API) popular among web developers to access &amp; manipulate web documents in HTML or XML using JavaScript.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img decoding=\"async\" width=\"626\" height=\"626\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-1.png\" alt=\"DOM\n\" class=\"wp-image-20328\" style=\"width:466px;height:466px\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-1.png 626w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-1-300x300.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-1-150x150.png 150w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-1-96x96.png 96w\" sizes=\"(max-width: 626px) 100vw, 626px\" title=\"\"><\/figure>\n\n\n\n<p><a href=\"https:\/\/www.guvi.in\/blog\/what-is-the-document-object-model-dom\/\">Document Object Model<\/a> is a tree-like representation of HTML elements in a web page that gets loaded into the browser. It comprises the structure and content of a document on the web page. While Selenium IDE can use the Document Object Model to access the web page elements.<\/p>\n\n\n\n<p>Big billion-dollar companies like Apple, Microsoft, Google, &amp; even Adobe are involved in standardizing the Document Object Model. Nonetheless, W3C (World Wide Web Consortium) is the main international standards organization that formalizes DOM Standard &amp; publishes it.&nbsp;<\/p>\n\n\n\n<p><em>Before diving into the next section, ensure you&#8217;re solid on full-stack development essentials like front-end frameworks, back-end technologies, and database management. If you are looking for a detailed Full Stack Development career program, you can join HCL GUVI\u2019s <a href=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=How+to+Master+DOM+in+Selenium+for+Beginners\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=How+to+Master+DOM+in+Selenium+for+Beginners\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Full Stack Development Course<\/strong><\/a> with placement assistance. You will be able to master the <a href=\"https:\/\/www.guvi.in\/blog\/guide-for-mern-stack\/\" target=\"_blank\" rel=\"noreferrer noopener\">MERN stack<\/a> (MongoDB, Express.js, React, Node.js) and build real-life projects.<\/em><\/p>\n\n\n\n<p><em>Additionally, if you want to explore JavaScript through a self-paced course, try HCL GUVI\u2019s <strong><a href=\"https:\/\/www.guvi.in\/courses\/web-development\/advanced-javascript\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=How+to+Master+DOM+in+Selenium+for+Beginners\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/courses\/web-development\/advanced-javascript\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=How+to+Master+DOM+in+Selenium+for+Beginners\" target=\"_blank\" rel=\"noreferrer noopener\">JavaScript certification course<\/a><\/strong>.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why is Understanding the DOM Structure Important?<\/strong><\/h2>\n\n\n\n<p>Understanding the Document Object Model(DOM) structure becomes important when you\u2019re willing to build any website using <a href=\"https:\/\/www.guvi.in\/hub\/javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\">Java<\/a>Script &amp; its related technologies. Furthermore, DOM is extremely essential when developing complicated tasks on your website as mentioned below.&nbsp;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" width=\"626\" height=\"626\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-2.png\" alt=\"DOM\" class=\"wp-image-20329\" style=\"width:480px;height:480px\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-2.png 626w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-2-300x300.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-2-150x150.png 150w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-2-96x96.png 96w\" sizes=\"(max-width: 626px) 100vw, 626px\" title=\"\"><\/figure><\/div>\n\n\n<ul>\n<li>Developing a webpage that <strong><a href=\"https:\/\/www.guvi.in\/blog\/data-driven-testing-in-selenium-using-jxl-part-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">automatically updates<\/a><\/strong> content without refreshing the entire page. Say, Cricbuzz live score updates are one such example.<\/li>\n\n\n\n<li>Handling user interactions such as adding or manipulating content dynamically.<\/li>\n\n\n\n<li>Building responsive web design\/content in your website. Here, responsive web design means creating a website that adapts itself to look good on all devices, such as Android, iPhone, tablets &amp; desktops, etc.<\/li>\n\n\n\n<li>Developing web page content that gives personalized experiences to users. Such as greeting the users\/customers by their first name while launching new offers on the web product.&nbsp;<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What are the Components of DOM in Selenium?<\/strong><\/h2>\n\n\n\n<p>DOM is one of the locators available in Selenium Web Driver. Since it uses the structure of the web page to locate the elements, we need to know the 3 main components of DOM:&nbsp;<\/p>\n\n\n\n<ul>\n<li>Window<\/li>\n\n\n\n<li>Document<\/li>\n\n\n\n<li>Element<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" width=\"1200\" height=\"900\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/window_document_html2_200.webp\" alt=\"Components of DOM in Selenium\" class=\"wp-image-13369\" style=\"width:448px;height:336px\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/window_document_html2_200.webp 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/window_document_html2_200-300x225.webp 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/window_document_html2_200-768x576.webp 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/window_document_html2_200-150x113.webp 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>Window<\/strong><\/h3>\n\n\n\n<p>A Window is a host object. It is implemented as the &#8220;global object&#8221; to complete an <a href=\"https:\/\/www.guvi.in\/blog\/features-of-ecmascript\/\" target=\"_blank\" rel=\"noreferrer noopener\">ECMAScript<\/a> implementation. In simple words, the Window object represents the browser&#8217;s window. It basically represents an open window in a browser &amp; supports almost all browsers. You\u2019ll see that all the global variables are properties &amp; functions are methods of the window object.<\/p>\n\n\n\n<p>The window object contains the document object in a DOM. While it sits on top of everything as a global object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Document<\/strong><\/h3>\n\n\n\n<p>The document sets the beginning of a DOM tree. It is the first node in a DOM. There are various methods and properties, whose scope applies to the entire document like URL, <a href=\"https:\/\/www.guvi.in\/blog\/javascript-queryselector-in-dom-manipulation\/\" target=\"_blank\" rel=\"noreferrer noopener\">querySelector<\/a>, getElementById, etc. While making a note that the document object is a property of the window object. So, typing window.document.write is the same as a document. write.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Element&nbsp;<\/strong><\/h3>\n\n\n\n<p>Element refers to any object represented by a node in a DOM tree of a document. Usually in HTML, the Element object represents HTML elements such as P(defines a paragraph), DIV(defines a division\/a section), A(defines a hyperlink), TABLE(defines an HTML table), or any other HTML element. Elements act as containers to hold text, elements, attributes, media objects, or all of these.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Locating Strategies using DOM in Selenium IDE<\/strong><\/h2>\n\n\n\n<p>We have four major ways to identify &amp; locate a web element using DOM.<\/p>\n\n\n\n<ol>\n<li>getElementById<\/li>\n\n\n\n<li>getElementsByName<\/li>\n\n\n\n<li>dom: index<\/li>\n\n\n\n<li>dom:name <\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" width=\"626\" height=\"418\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-3.png\" alt=\"DOM in Selenium IDE\" class=\"wp-image-20330\" style=\"width:491px;height:328px\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-3.png 626w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-3-300x200.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-3-150x100.png 150w\" sizes=\"(max-width: 626px) 100vw, 626px\" title=\"\"><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">1.getElementByID<\/h3>\n\n\n\n<ul>\n<li>The&nbsp;<code>getElementById()<\/code>&nbsp;method is one of the most commonly used methods in the HTML DOM. <\/li>\n\n\n\n<li>The&nbsp;<code>getElementById()<\/code>&nbsp;method will return an element with a specified value if the element exists with an Id.<\/li>\n\n\n\n<li>The&nbsp;<code>getElementById()<\/code>&nbsp;method will return &#8216;<code>null<\/code>&#8216;&nbsp;if the element does not exist.<\/li>\n\n\n\n<li><strong>Syntax script:<\/strong> document.getElementById(&#8220;id of the element&#8221;)<\/li>\n\n\n\n<li>Here, the &#8216;Id of the element&#8217; refers to &#8216;the value of the Id attribute&#8217; that is being accessed.<\/li>\n\n\n\n<li>For example, while registration process in any website, we will define the Document Object Model value for the &#8220;Username&#8221; text box of any registration\/login page as:&nbsp;<strong>document.getElementById(&#8220;email&#8221;)<\/strong><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.getElementsByName<\/h3>\n\n\n\n<ul>\n<li>The&nbsp;<code>getElementsByName()<\/code>&nbsp;method will return a collection of elements with a specified name. <\/li>\n\n\n\n<li>The&nbsp;<code>getElementsByName()<\/code>&nbsp;method can return a&nbsp;NodeList(live). &nbsp;<\/li>\n\n\n\n<li>An array-like collection (list) of nodes is known as a <strong>NodeList<\/strong>. <\/li>\n\n\n\n<li>All of these nodes in the list can be accessed by index. The list index starts at 0.<\/li>\n\n\n\n<li><strong>Syntax script:<\/strong> document.getElementByName(&#8220;name&#8221;)[index] <\/li>\n\n\n\n<li>Here, &#8220;<strong>name<\/strong>&#8221; refers to the value of name attribute that is being accessed.<\/li>\n\n\n\n<li>And, &#8220;<strong>index<\/strong>&#8221; refers to an integer value used to specify the location of the desired element.<\/li>\n\n\n\n<li>For example, while the registration process through forms on any website, we will define the Document Object Model value for the &#8220;Username&#8221; text box of any registration\/login page as: <strong>document.getElementByName(&#8220;email_id&#8221;)<\/strong><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. dom:index<\/h3>\n\n\n\n<p>With this method, you can access a particular form control in the returned collection by using the index attributes. Again, consider a registration process through the form in any website, we will define the Document Object Model values with index as below.<\/p>\n\n\n\n<ul>\n<li><strong>Syntax Script :<\/strong> document.forms[index of the form].elements[index of the element]<\/li>\n\n\n\n<li>Here, &#8220;<strong>Index of the form<\/strong>&#8221; refers to the integer value of the index (starting at 0) of the form with respect to the whole page.<\/li>\n\n\n\n<li>And, &#8220;<strong>Index of the element<\/strong>&#8221; refers to the integer value of the index (starting at 0) of the form with respect to the whole form that contains it.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. dom:name<\/h3>\n\n\n\n<p>Considering the same registration process in any website, we will define the Document Object Model values with &#8220;Name of the form&#8221; &amp; &#8220;Name of the element&#8221;.<\/p>\n\n\n\n<ul>\n<li><strong>Syntax script:<\/strong> document.forms[&#8220;name of the form&#8221;].elements[&#8220;name of the element&#8221;]<\/li>\n\n\n\n<li>Here, &#8220;<strong>Name of the form<\/strong>&#8221; refers to the value of the name attribute of the form tag that contains the element you want to access.<\/li>\n\n\n\n<li>And, &#8220;<strong>Name of the element<\/strong>&#8221; refers to the value of the name attribute of the element you want to access.<\/li>\n\n\n\n<li>Example:&nbsp;<strong>&#8220;document.forms[&#8220;homepage&#8221;].elements[&#8220;userName&#8221;]&#8221;<\/strong><\/li>\n\n\n\n<li>Make a note that this method is applied only to elements within a named form.<\/li>\n<\/ul>\n\n\n\n<p>Kickstart your Full Stack Development journey by enrolling in HCL GUVI&#8217;s certified <a href=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=How+to+Master+DOM+in+Selenium+for+Beginners\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=How+to+Master+DOM+in+Selenium+for+Beginners\" target=\"_blank\" rel=\"noreferrer noopener\">Full Stack Development Course<\/a> with placement assistance where you will master the MERN stack (MongoDB, Express.js, React, Node.js) and build interesting real-life projects. This program is crafted by our team of experts to help you upskill and assist you in placements. Alternatively, if you want to explore JavaScript through a self-paced course, try HCL GUVI\u2019s <a href=\"https:\/\/www.guvi.in\/courses\/web-development\/advanced-javascript\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=How+to+Master+DOM+in+Selenium+for+Beginners\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/courses\/web-development\/advanced-javascript\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=How+to+Master+DOM+in+Selenium+for+Beginners\" target=\"_blank\" rel=\"noreferrer noopener\">JavaScript course.<\/a><\/p>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1688389363841\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is DOM concept in Selenium?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The Document Object Model (DOM) in Selenium is a programming interface that represents the structure of an HTML or XML document. It provides a way to access and manipulate the elements and content of a web page. With the DOM, Selenium can interact with web elements, perform actions like clicking buttons or entering text, and extract information from the page. It enables test automation by allowing testers to simulate user interactions and validate the behavior of web applications.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1688389524052\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is DOM and POM in Selenium?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The Document Object Model (DOM) is a programming interface that represents the structure and content of a web page as objects. The Page Object Model (POM) is a design pattern in Selenium that organizes web page elements and their interactions into reusable objects, enhancing test maintenance and readability.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1688389607304\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is DOM and what is it used for?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The Document Object Model is a programming interface that represents the structure of an HTML or XML document as a tree-like structure. It provides a way for programs to access, manipulate, and update the content, structure, and style of web pages. The Document Object Moel is commonly used in web development to dynamically modify and interact with web page elements using JavaScript or other scripting languages.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1688389664043\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is the difference between XPath and DOM in Selenium?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>XPath and DOM are both commonly used in Selenium for web automation. XPath is a language for navigating XML\/HTML documents and allows locating elements based on their attributes or hierarchical relationships. Document Object Model, on the other hand, is a programming interface that represents the structure of an HTML\/XML document, enabling manipulation and traversal of elements.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>DOM stands for \u2018Document Object Model\u2019. In simple words, the DOM is used by web developers to make changes in the document structure, style, and content of a web page. Thus, DOM in Selenium WebDriver is considered as an important component in web development using HTML5 &amp; JavaScript.&nbsp; What is DOM and Its Importance In [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":20327,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40,706],"tags":[],"views":"17917","authorinfo":{"name":"Lahari Chandana","url":"https:\/\/www.guvi.in\/blog\/author\/lahari-chandana\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image-300x240.png","jetpack_featured_media_url":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/07\/image.png","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/13289"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=13289"}],"version-history":[{"count":21,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/13289\/revisions"}],"predecessor-version":[{"id":88915,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/13289\/revisions\/88915"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/20327"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=13289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=13289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=13289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}