Role of HTML in Automation - Introduction to HTML

 

Understanding HTML: A Guide for Beginners

As an experienced test engineer, I've worked extensively with HTML, the foundational language of the web. HTML stands for HyperText Markup Language, and it's used to display data in a structured format in web browsers. Let’s dive into the basics of HTML to give you a clear picture of how it works.

What is HTML?

HTML is a markup language that uses tags to structure content on the web. These tags, enclosed in angle brackets < >, tell the browser how to display text, images, and other elements on a webpage. HTML is a tree-structured, case-insensitive language, meaning it’s not affected by uppercase or lowercase letters.

Basic Structure of HTML

Every HTML document starts with the <html> tag, which is the root of the document. This tag has two main child tags: <head> and <body>.

  • <head>: Contains meta-information about the document, such as its title.
  • <body>: Contains the content that is displayed on the webpage.

Here's a simple HTML code example:

<html>

    <head>

          <title>Selenium Demo</title>

    </head>

    <body>

          <h1>Demo Page For HTML</h1>

          <span>Username</span>

          <input type="text" id="123" name="abhishek"><br>

          <span>Password</span>

          <input type="text" id="345" name="arun"><br>

          <input type="checkbox">

          <span>Remember Me</span><br>

          <input type="radio">

          <span>Male</span>

          <input type="radio">

          <span>Female</span>

          <input type="radio">

          <span>Others</span><br>

          <button type="submit">Login</button>

          <a href="https://www.qspiders.com/">Goto Qspiders</a>

    </body>

</html>

Key Concepts in HTML

  1. Tags: The building blocks of HTML. They are enclosed in angle brackets, like <a>. Tags can be opening tags (e.g., <a>) or closing tags (e.g., </a>).

  2. Tag Name: The first word inside a tag. For example, in <a href="https://www.google.com">, the tag name is a.

  3. Attributes: Provide additional information about an element. Attributes are always in the form of a key-value pair, such as href="https://www.google.com". One tag can have multiple attributes or none at all.

  4. Attribute Name: The key in the key-value pair of an attribute. In <input type="text">, type is the attribute name.

  5. Attribute Value: The value in the key-value pair of an attribute. In <input type="text">, text is the attribute value. Attribute values are not always mandatory.

  6. Text: Anything between an opening and closing tag. For example, in <a href="https://www.google.com/">Google</a>, Google is the text.

  7. Link Text: The text between anchor (<a>) tags, which is clickable and directs to a link. For example, in <a href="https://www.google.com/">Google</a>, Google is the link text.

Why Understanding HTML is Essential for Automation

When it comes to automation testing, understanding HTML is crucial for several reasons. One of the primary reasons is the concept of locators and the WebElement interface.

Locators: In automation testing tools like Selenium, locators are used to find elements on a webpage. These elements can be buttons, text fields, links, etc. Locators use HTML attributes such as id, name, class, tag name, and others to identify and interact with these elements.

WebElement Interface: The WebElement interface represents an HTML element. Through this interface, you can perform various actions on the web elements, such as clicking a button, entering text into a text field, or extracting text from an element.

Understanding HTML helps you:

  • Identify Elements: By knowing the structure of HTML and the significance of tags and attributes, you can efficiently identify and interact with web elements.
  • Write Efficient Locators: You can write more accurate and efficient locators using different strategies (e.g., ID, name, XPath, CSS selectors) to interact with elements during automation.
  • Debug Issues: When automation scripts fail, understanding HTML helps in debugging the issues by inspecting the HTML structure of the webpage and finding out if the locators are correct or if there are changes in the HTML that need to be addressed.

By mastering HTML, you enhance your ability to create robust and reliable automation scripts, ensuring that your tests accurately simulate user interactions and verify the functionality of web applications.

Sample HTML Explained

In the sample HTML code provided, we have various elements demonstrating different HTML tags and attributes:

  • <h1>: A header tag that displays large, bold text.
  • <span>: An inline container used to mark up a part of a text or a document.
  • <input>: Used to create input fields, like text boxes and checkboxes.
  • <button>: Creates a clickable button.
  • <a>: An anchor tag used to create hyperlinks.

Each tag serves a specific purpose and helps in structuring the content effectively.

By understanding these fundamental concepts, you’ll be able to create and comprehend HTML documents more efficiently. HTML forms the backbone of web development, and mastering it is essential for anyone looking to build or test web applications.


@author Akash Deb (SDET)


Comments

Popular posts from this blog

Introduction To Selenium

Introduction to Automation

Handling Browser Window