Locators are used to identify web elements on a webpage so that Selenium can interact with them.

  • id
  • name
  • className
  • tagName
  • linkText
  • partialLinkText
  • xpath
  • cssSelector

XPath is a locator strategy used to navigate through XML/HTML DOM structure.

Types:

  • Absolute XPath → starts from root (/html/body/...) ❌ not recommended
  • Relative XPath → flexible and stable (//input[@id='email']) ✅

XPath is useful for:

  • Dynamic elements
  • Complex structures

The Page Object Model (POM) is a design pattern used in test automation that helps you create clean, maintainable, and reusable test code — especially for web applications.

In POM, each web page of your application is represented by a separate class (a “Page Object”), and all the elements (buttons, fields, links, etc.) and actions (clicks, form submissions, etc.) on that page are defined as methods in that class.

Better Code Organization
Keeps UI locators and actions in one place.

Reusability
You can use the same page object in multiple tests.

Easier Maintenance
If a page changes, you update only one file — not all your test scripts.

Improved Readability
Tests become more readable and behave like real-world actions.

TestNG is a testing framework that helps organize, execute, and manage automated tests efficiently. It supports features like test grouping, prioritization, parallel execution, and data-driven testing.

It also generates detailed reports and integrates well with tools like Selenium and CI/CD pipelines

Waits are used to handle synchronization issues when elements take time to load. Without waits, Selenium may try to interact with elements before they are available, causing failures.

Types:

  • Implicit Wait → applies globally
  • Explicit Wait → waits for specific condition
  • Fluent Wait → customizable

Best practice:
Use Explicit Wait for better control.

Implicit wait is applied globally and waits for all elements, whereas explicit wait is applied to specific elements based on conditions.

Example:

  • Wait until element is clickable
  • Wait until element is visible

Explicit wait is preferred because it is more efficient and avoids unnecessary delays.

Dropdowns are handled using the Select class in Selenium when the HTML uses <select> tag.

We can select options using:

  • Visible text
  • Value
  • Index

For custom dropdowns (non-select):
We use click and XPath.

Alerts are popups that require user action. Selenium handles them using switchTo().alert().

Operations:

  • accept() → click OK
  • dismiss() → click Cancel
  • getText() → read message

Important:
You must switch to alert before interacting with it.

This exception occurs when the element is no longer attached to the DOM. It usually happens when

  • Page refreshes
  • DOM updates dynamically

Solution:

  • Re-locate the element
  • Use explicit wait

Actions class is used to perform advanced user interactions that cannot be done using simple commands

Examples:

  • Mouse hover
  • Drag and drop
  • Right-click

Used in complex UI scenarios.

JavaScriptExecutor allows executing JavaScript code inside the browser.

Used when:

  • Selenium cannot click element
  • Need to scroll page
  • Handle hidden elements

Example:

         js.executeScript(“window.scrollBy(0,500)”);

In this approach, test data is stored externally (Excel, CSV, JSON), and tests are executed using different data sets.

Benefits:

  • Reusability
  • Multiple test scenarios
  • Better coverage

Failures are handled using:

  • Retry mechanism
  • Screenshot capture
  • Logging (Log4j)
  • Reports (Extent Reports)

Navigation commands are used to move between pages.

Methods:

  • get() → open URL
  • navigate().to() → go to URL
  • navigate().back() → go back
  • navigate().forward() → go forward
  • navigate().refresh() → refresh page 
  •  findElement → returns a single element, throws exception if not found
  •  findElements → returns a list of elements, returns empty list if not found

Frames are handled using switchTo().frame().

Types:

  • By index
  • By name/id
  • By WebElement

Page Factory is an extension of POM that uses @FindBy annotation to initialize elements.

Fluent Wait is an advanced wait with customizable timeout and polling interval.

Features:

  •   Ignore specific exceptions
  •   Set polling frequency

Examples:

  • NoSuchElementException
  • TimeoutException
  • StaleElementReferenceException
  • ElementNotInteractableException

Using TakesScreenshot interface.

Used for:

  •  Failure analysis
  •  Reporting

Using JavaScriptExecutor.

Examples:

  •  scrollBy()
  •  scrollIntoView()

 Use getWindowHandles() and switchTo().window()

Steps:

  •  Store window IDs
  •  Switch between them

Using TestNG RetryAnalyzer or custom logic to rerun failed tests.

Use:

  •  Page Object Model
  •  Reusable utilities
  •  Data-driven approach
  •  Proper logging & reporting
  •  Hard Assert → stops execution on failure
  •  Soft Assert → continues execution and reports all failures at end

Using tools like:

  •  Jenkins
  •  GitHub Actions

Steps:

  •  Trigger tests on build
  •  Run tests automatically
  •  Generate reports

Logging helps track test execution.

Tools:

  •  Log4j
  •  SLF4J

 Using:

  •  @DataProvider
  •  @Test parameters
  •  Use stable locators
  •  Avoid Thread.sleep
  •  Use Page Object Model (POM)
  •  Keep tests independent
  •  Maintain reusable code

A broken link is a hyperlink that does not work or leads to an error page (like 404 Not Found), usually because the target page is missing or invalid.

  • driver.close() → closes current browser window
  • driver.quit() → closes all browser windows and ends session
  • getText() → gets visible text
  • getAttribute() → gets attribute value (like value, href)

WebElement represents an HTML element in Selenium.

Used to perform actions like:

  • click()
  • sendKeys()
  • getText()

Maven is a build automation tool.

Used for:

  • Managing dependencies
  • Running tests
  • Project structure

Jenkins is a CI/CD tool used to automate test execution.

Used for:

  • Scheduling test runs
  • Integrating with Git
  • Generating reports

Methods:

  • isDisplayed()
  • isEnabled()
  • isSelected()

Used for validation in test cases

  • click(): Clicks any element
  • submit(): submit a form

Selenium cannot interact directly.

Solution:

  • Use JavaScriptExecutor
  • Remove disabled attribute
  • getWindowHandle(): Returns single window ID
  • getWindowHandles(): Returns all window IDs

Steps:

  • Locate table
  • Use loops for rows and columns
  • Use dynamic XPath

Best practice:

  • Use Explicit Wait
  • Avoid mixing waits
  • Avoid Thread.sleep()

Best practices:

  • Use stable locators
  • Use waits properly
  • Keep tests independent

Steps:

  • Enter text
  • Capture suggestions
  • Loop and select

DOM (Document Object Model) represents the structure of a webpage.

Used for:

  • Locating elements
  • Understanding hierarchy

Dynamic elements change attributes like id or class at runtime.

Solution:

  • Use relative XPath
  • Use functions like: contains() ,starts-with()
  • Use stable attributes

Example:
//input[contains(@id,’user’)]

This is called flaky tests.

Approach:

  • Add proper waits (Explicit Wait)
  • Check synchronization issues
  • Verify locators
  • Add logging and screenshots

If input type=”file”:

Use sendKeys() with file path

If custom upload:

Use AutoIT or Robot class

Selenium cannot directly handle OS-level downloads.

Solution:

  • Set browser download preferences
  • Verify file in download folder

Steps:

  • Get all links using findElements(By.tagName(“a”))
  • Use HTTP connection
  • Check response code

Codes:

  • 200 → OK
  • 404 → Broken

Using JavaScriptExecutor:

scrollIntoView()

Shadow DOM elements are hidden inside shadow root.

Solution:

  • Use JavaScriptExecutor
  • Access shadowRoot

get():

  • Waits for page load
  • Used for initial load

navigate().to():

  • Similar but used for navigation

Using TestNG:

  • parallel=”methods” or “classes” in XML
  • Use Selenium Grid

Using:

  • Excel (Apache POI)
  • JSON
  • DataProvider in TestNG

Solution:

  • Re-locate element
  • Use Explicit Wait
  • Avoid storing WebElement for long
  • Dynamic elements
  • Synchronization issues
  • Browser compatibility
  • Slow execution

Check:

  • Visibility
  • Enabled state
  • Overlapping elements

Use:

Explicit Wait → elementToBeClickable

Steps:

  • Check logs
  • Check screenshots
  • Re-run test
  • Validate locators
  • Check environment

Methods:

  • addCookie()
  • getCookies()
  • deleteCookie()

Steps:

  • Push code to Git
  • Configure Jenkins job
  • Trigger build
  • Run tests
  • Generate report

Using:

  • TestNG listeners (ITestListener)
  • Take screenshot in onTestFailure()

Absolute:

  • Full path
  • Not stable

Relative:

  • Flexible
  • Recommended

Possible reasons:

  • Different browser behavior
  • Locator compatibility issues
  • Timing issues

Solution:

  • Use cross-browser compatible locators
  • Add explicit waits
  • Use browser-specific options if needed

Possible causes:

  • Element overlapped by another element
  • Element not clickable yet
  • Hidden behind loader

Solution:

  • Use Explicit Wait → elementToBeClickable
  • Scroll into view
  • Use JavaScriptExecutor click as fallback

Reasons:

  • Element inside iframe
  • Element inside shadow DOM
  • Page not fully loaded

Solution:

  • Switch to frame
  • Handle shadow root
  • Use wait

Solution:

  • Use JavaScriptExecutor to scroll
  • Load elements dynamically
  • Use loop until element appears

Solution:

  • Use contains() or starts-with()
  • Use parent-child XPath
  • Use other stable attributes

Common reasons:

  • Environment difference
  • Headless mode issues
  • Timing issues

Solution:

  • Add proper waits
  • Check environment configs
  • Add logging

Solution:

  • Use DataProvider
  • Store test data externally
  • Parameterize login

Types:

  • Simple → sendKeys()
  • Complex → click through UI

Steps:

  • Open calendar
  • Navigate month/year
  • Select date

Solution:

  • Loop through pages
  • Click “Next” button
  • Extract data until last page

Steps:

  • Set download directory
  • Check file existence
  • Validate file name

Optimization:

  • Run tests in parallel
  • Remove Thread.sleep()
  • Use headless mode
  • Optimize locators

Solution:

  • Avoid dependency (best practice)
  • Use TestNG dependsOnMethods if needed

Approach:

  • Use DataProvider
  • Pass multiple datasets

Example:

  • Invalid username
  • Invalid password
  • Empty fields

Solution:

  • Use POM design
  • Centralize locators
  • Use stable attributes

Steps:

  • Capture element text
  • Compare with expected

Use:

assertEquals()

For testing web-based applications, Selenium can be used.

The test types supported by Selenium are:

  • Functional testing: It verifies if each function of a software application performs in accordance with specific requirements. This testing primarily involves black-box testing, and it is not concerned with the source code of the application.
  •  Regression testing: It is nothing but a full or partial selection of the already executed test cases to be re-executed to ensure that the existing functionalities work fine.

Breakpoints: Breakpoints are used to stall the execution of the test. The execution will stop whenever a breakpoint is implemented, and this will help us check whether the code is working properly or not.

Start points: Start points are the points from where the execution should begin. Start points can be used when we want to run the test script from the middle of the code or after a breakpoint.

Inspecting webpage structure using browser DevTools.

Used for:

  • Locators
  • XPath
  • CSS selectors

Features:

  • Relative locators
  • Selenium Manager
  • Improved Grid
  • Better DevTools support
  • New window/tab handling

Small set of critical test cases executed after every build.

Purpose:

  • Verify build stability quickly.

Preferred locator order:

  1. ID
  2. Name
  3. CSS Selector
  4. XPath

Because IDs are fastest and most stable.

Tests that:

  • Pass sometimes
  • Fail sometimes

Reasons:

  • Timing issues
  • Dynamic elements
  • Environment instability
  • Use explicit waits
  • Stable locators
  • Retry mechanism
  • Proper synchronization
  • Independent tests
  • Pass/fail percentage
  • Automation coverage
  • Execution time
  • Defect leakage
  • Stability rate

Popular reporting tools:

  • Extent Reports
  • Allure Reports
  • TestNG Reports

Advanced HTML reporting library used for:

  • Logs
  • Screenshots
  • Execution reports
VerificationValidation
Checks whether product is built correctlyChecks whether correct product is built
Process-orientedProduct-oriented

Used in parallel execution to maintain separate WebDriver instances per thread.

Example use:

  • Parallel test execution in TestNG

Usually OTP is not automated directly.

Approaches:

  • Disable OTP in test environment
  • Fetch OTP from database/API/email
  • Use static OTP in lower environments
  • Use relative XPath/CSS
  • Coordinate with developers
  • Add stable attributes like data-testid
  • Database comparison
  • API validation
  • Dynamic table handling

Approaches:

  • Generate test data dynamically
  • Use APIs/database
  • Mock services

Never hardcode credentials.

Use:

  • Environment variables
  • Vault tools
  • Encrypted config

Check:

  • Image displayed
  • HTTP response
  • Natural width > 0

Using:

  • JavaScriptExecutor
  • Actions class
  • Wait until visible

Use:

  • Relative XPath
  • Parent-child relationship
  • CSS hierarchy
  • Multiple attributes

A Keyword-Driven Framework is an automation framework where test actions are represented using predefined keywords like Click, Type, and Login.

The test data, locators, and actions are maintained separately from the test scripts, making the framework more reusable, maintainable, and easy to understand.