πŸ” Interview Prep Questions

What is Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Selenium is a widely used open-source framework for automating web applications. It supports multiple programming languages such as Java, Python, C#, etc., and can automate browser interactions like clicking buttons, filling out forms, etc.

What are the components of Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Selenium consists of four main components: 1. Selenium IDE – A browser plugin for recording and playback of tests. 2. Selenium RC (Remote Control) – Allows running tests on remote servers. 3. Selenium WebDriver – A programming interface for controlling the browser programmatically. 4. Selenium Grid – A tool for running tests on multiple machines simultaneously.

Which browsers does Selenium WebDriver support?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Selenium WebDriver supports all major browsers including: 1. Google Chrome 2. Mozilla Firefox 3. Internet Explorer 4. Safari 5. Edge Additionally, WebDriver can be used with headless browsers like Chrome Headless and Firefox Headless.

What is Selenium WebDriver?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Selenium WebDriver is a programming interface used to interact with and control web browsers. It is an improvement over Selenium RC, providing a more efficient and flexible way of automating browser actions using various programming languages like Java, Python, and C#.

What are the differences between Selenium 1 and Selenium 2?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Selenium 1 (Selenium RC) uses a JavaScript-based method to control the browser, whereas Selenium 2 (WebDriver) directly communicates with the browser and is faster and more reliable. WebDriver also supports better synchronization and more advanced features like handling dynamic content.

What is the difference between Selenium RC and WebDriver?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Selenium RC uses a JavaScript injection technique to automate browsers, which leads to slower execution. WebDriver, on the other hand, directly controls the browser, making it faster and more efficient. WebDriver also handles dynamic elements better and has better support for modern browsers.

Name the different types of WebDriver.

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
There are several types of WebDriver implementations available in Selenium: 1. ChromeDriver – For controlling Google Chrome. 2. FirefoxDriver – For controlling Mozilla Firefox. 3. InternetExplorerDriver – For controlling Internet Explorer. 4. SafariDriver – For controlling Safari. 5. EdgeDriver – For controlling Microsoft Edge. 6. HtmlUnitDriver – A headless browser for running tests without UI.

What are the major advantages of using Selenium WebDriver?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The major advantages of using Selenium WebDriver are: 1. Cross-browser compatibility. 2. Support for various programming languages. 3. Integration with other testing tools like TestNG and JUnit. 4. High performance due to direct browser interaction. 5. Large community support and open-source nature.

Can Selenium handle window-based pop-ups?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Selenium cannot directly handle window-based pop-ups (e.g., Windows OS alerts). However, it can handle browser pop-ups like JavaScript alerts, confirm, and prompt dialogs using the Alert interface in WebDriver.

How do you launch a browser using WebDriver?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To launch a browser using WebDriver, you can instantiate the browser driver class like this: - For Chrome: WebDriver driver = new ChromeDriver(); - For Firefox: WebDriver driver = new FirefoxDriver(); - For Edge: WebDriver driver = new EdgeDriver();

What is the get() method used for in WebDriver?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The get() method in WebDriver is used to navigate to a specified URL. It takes a single string parameter, which is the URL of the web page to be opened in the browser.

How do you navigate between pages using Selenium WebDriver?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can navigate between pages using the following methods in WebDriver: 1. `driver.get("URL")` – To open a new page. 2. `driver.navigate().back()` – To go back to the previous page. 3. `driver.navigate().forward()` – To move forward to the next page. 4. `driver.navigate().refresh()` – To refresh the current page.

What are some limitations of Selenium WebDriver?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Some limitations of Selenium WebDriver include: 1. It cannot handle window-based pop-ups like file upload dialogs. 2. Selenium is not suitable for performance testing. 3. It cannot interact with non-browser-based applications. 4. Lack of support for advanced image or visual-based testing. 5. Requires an external tool for cross-browser testing on multiple devices.

How do you close the current window in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To close the current window in Selenium, use the `driver.close()` method. This will close the browser window that the WebDriver is currently controlling.

How do you quit all browser windows in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To quit all browser windows and terminate the WebDriver session, use the `driver.quit()` method. This will close all associated browser windows and terminate the WebDriver instance.

What is the use of findElement() in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `findElement()` method in Selenium is used to locate a single element on the web page based on a specified locator strategy (like ID, class, name, XPath, etc.). It returns a WebElement object for interaction.

What is the difference between driver.close() and driver.quit()?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `driver.close()` method closes the current browser window, while `driver.quit()` closes all the windows and ends the WebDriver session, releasing all resources used.

What is the difference between getTitle() and getPageSource() in WebDriver?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
`getTitle()` returns the title of the current web page as a string, while `getPageSource()` returns the entire HTML source of the page as a string.

What is the purpose of getWindowHandle() in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `getWindowHandle()` method returns a unique identifier for the current window. This is useful when working with multiple windows or tabs, allowing you to switch between them.

What are some exceptions in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Some common exceptions in Selenium include: 1. NoSuchElementException – Thrown when an element cannot be found. 2. TimeoutException – Occurs when a timeout is exceeded during an operation. 3. ElementNotVisibleException – Raised when an element is present but not visible. 4. StaleElementReferenceException – Happens when a reference to an element becomes invalid. 5. WebDriverException – A general exception for WebDriver-related issues.

How do you handle NoSuchElementException in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To handle the `NoSuchElementException`, you can: 1. Use `try-catch` blocks to catch the exception and take necessary actions. 2. Wait for the element to be visible or present before interacting with it using implicit or explicit waits. 3. Verify the locator to ensure it is correct and the element is available in the DOM.

What is the StaleElementReferenceException and how do you handle it?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `StaleElementReferenceException` occurs when an element that was previously found becomes stale or no longer exists in the DOM (e.g., after a page refresh or DOM update). To handle this, you can: 1. Re-locate the element. 2. Use waits to ensure the element is available again. 3. Wrap interactions with elements in a `try-catch` block and retry actions.

Can you use Selenium for performance testing?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Selenium is not typically used for performance testing. It is primarily a functional testing tool. However, you can measure load times using Selenium, but it doesn't provide robust features for performance analysis like tools such as JMeter or LoadRunner. Selenium can be used to simulate user actions for performance testing but does not offer detailed metrics or analysis.

What are the locators available in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The available locators in Selenium are: 1. ID (`By.id()`): Locates elements by their ID attribute. 2. Name (`By.name()`): Locates elements by their name attribute. 3. Class Name (`By.className()`): Locates elements by their class name. 4. Tag Name (`By.tagName()`): Locates elements by their tag name (e.g., `input`, `div`). 5. Link Text (`By.linkText()`): Locates links by their exact text. 6. Partial Link Text (`By.partialLinkText()`): Locates links by a substring of their text. 7. XPath (`By.xpath()`): Locates elements using an XPath expression. 8. CSS Selector (`By.cssSelector()`): Locates elements using a CSS selector.

What is XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
XPath (XML Path Language) is a query language used to locate elements in an XML document (or HTML in the case of Selenium). It allows you to navigate through the elements and attributes in an HTML page using various methods such as absolute or relative paths, conditions, and axes.

What is a CSS Selector in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
A CSS Selector is a pattern used to select HTML elements based on their attributes, like class, id, type, or other properties. It is a more compact way of identifying elements compared to XPath, and it is supported by modern web browsers for efficient element lookup in Selenium.

What is the difference between absolute XPath and relative XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
- Absolute XPath: This starts from the root element (`/html/body/...`). It provides the complete path to an element, but it is more brittle as changes in the DOM can break it. - Relative XPath: This starts from any element in the DOM (e.g., `//div[@class='example']`). It is more flexible and resistant to changes in the DOM structure.

What is the difference between findElement() and findElements()?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
- `findElement()`: Locates a single element on the page and returns the first matching element. It throws a `NoSuchElementException` if no element is found. - `findElements()`: Locates all elements that match the locator and returns a list. If no element is found, it returns an empty list.

What are the advantages of using CSS selectors?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Advantages of using CSS selectors include: 1. They are more concise than XPath. 2. They are faster in locating elements. 3. They are widely supported across different browsers. 4. They allow for advanced selection techniques like pseudo-classes (`:nth-child`) and attribute-based matching.

What is an ID locator in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
An ID locator in Selenium is used to locate elements by their unique `id` attribute. Since IDs are generally unique within a page, this is one of the fastest and most reliable locator strategies for finding elements.

How do you use the name locator in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can use the name locator in Selenium by identifying an element with its `name` attribute. Use `By.name()` method to find the element: ```java WebElement element = driver.findElement(By.name("element_name")); ```

How do you locate an element using its class name in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To locate an element using its class name, you can use the `By.className()` method: ```java WebElement element = driver.findElement(By.className("element_class")); ```

What is an absolute XPath in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
An absolute XPath in Selenium is the complete path from the root element (``) to the target element. It starts with `/` and specifies each node along the path. Example: ```xpath /html/body/div[1]/div[2]/input ``` This approach is fragile as changes in the DOM structure can break the XPath.

What is a relative XPath in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
A relative XPath in Selenium is a more flexible way of locating elements by using `//` instead of `/` to start the XPath. It allows you to locate an element anywhere in the document. Example: ```xpath //input[@name='username'] ``` This can be used even if the element is nested within multiple layers of HTML.

What is the difference between XPath and CSS selectors in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
- XPath: XPath is a powerful way to traverse and locate elements in the DOM. It can traverse both up and down the DOM tree using various axes, and supports more complex expressions. However, it is slower compared to CSS selectors. - CSS Selectors: CSS selectors are faster than XPath and are easier to write. They allow you to select elements based on their CSS attributes (e.g., `class`, `id`, `attributes`). CSS selectors are not as flexible as XPath for traversing the DOM.

How do you write XPath for an element containing specific text?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To write an XPath for an element containing specific text, use the `contains()` function in XPath: ```xpath //button[contains(text(), 'Submit')] ``` This locates any button element that contains the word "Submit".

How do you find elements by link text in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To find elements by link text in Selenium, use the `By.linkText()` method: ```java WebElement link = driver.findElement(By.linkText("Home")); ``` This will find a link with the exact text "Home".

How do you locate an element using partial link text?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To locate an element using partial link text, use the `By.partialLinkText()` method: ```java WebElement link = driver.findElement(By.partialLinkText("Home")); ``` This will find a link that contains the partial text "Home".

What is the By class in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `By` class in Selenium is used to define various methods to locate elements. You can use it to specify locators like ID, name, XPath, CSS selectors, class name, etc. It acts as a reference to locate web elements: ```java By.id("element_id"); By.name("element_name"); By.xpath("//div[@id='element_id']"); ```

How do you locate elements by tag name in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To locate an element by tag name, you can use the `By.tagName()` method: ```java WebElement element = driver.findElement(By.tagName("input")); ``` This will locate the first `input` tag on the page.

What is the purpose of starts-with in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `starts-with()` function in XPath is used to locate an element whose attribute value starts with a specific string. It's useful for locating elements when the full value of the attribute is not known.
//input[starts-with(@id, 'user')]
This will locate any `input` element whose `id` attribute starts with 'user'.

What is the use of contains() in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `contains()` function in XPath is used to check if an element's attribute contains a specific substring. This is particularly helpful when the attribute value may change dynamically.
//div[contains(@class, 'active')]
This will select any `div` element whose `class` attribute contains the substring 'active'.

How do you handle dynamic elements using XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To handle dynamic elements in XPath, you can use functions like `contains()` or `starts-with()` to create more flexible and robust locators. Additionally, using relative XPath instead of absolute XPath helps in cases where the structure of the DOM changes.
//button[contains(@id, 'submit')]
This allows you to locate elements even if parts of their attributes are dynamic.

How do you use the following-sibling axis in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `following-sibling` axis in XPath is used to locate elements that share the same parent and come after the current node.
//h2[text()='Title']/following-sibling::p
This will find a `p` element that is the next sibling of an `h2` element containing the text 'Title'.

How do you use preceding-sibling in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `preceding-sibling` axis in XPath is used to locate elements that share the same parent and come before the current node.
//h2[text()='Title']/preceding-sibling::div
This will find a `div` element that is the previous sibling of an `h2` element containing the text 'Title'.

How do you use the ancestor axis in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `ancestor` axis in XPath is used to locate all ancestors (parent, grandparent, etc.) of the current node.
//span[text()='Text']/ancestor::div
This will find the `div` element that is an ancestor of a `span` element containing the text 'Text'.

How do you locate child elements using XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To locate child elements using XPath, you can use the `/` operator to indicate direct children of an element.
//div/child::span
This will find any `span` element that is a direct child of a `div` element.

How do you locate parent elements using XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To locate parent elements using XPath, you can use the `parent::` axis.
//span[text()='Text']/parent::div
This will find the parent `div` element of a `span` element containing the text 'Text'.

What is the last() function in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `last()` function in XPath is used to select the last element from a set of elements.
//div[last()]
This will select the last `div` element in the document or the node set.

What is the use of position() in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `position()` function in XPath is used to select elements based on their position in a set of nodes.
//div[position()=1]
This will select the first `div` element in the document.

How do you locate elements by attributes in CSS selectors?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
In CSS selectors, you can locate elements by attributes using the format `[attribute='value']`. For example:
input[type='text']
This will locate all `input` elements with the type 'text'.

How do you find elements that contain a specific substring in CSS selectors?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can use the `*=` operator in CSS selectors to find elements whose attribute contains a specific substring. For example:
a[href*='example']
This will locate all `a` elements whose `href` attribute contains 'example'.

What is the difference between == and = in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
In XPath, `=` is used for comparison between an element's attribute and a specific value. `==` is used for comparing two values for equality (in languages like Java or JavaScript). Example:
//input[@id='submit' and @type='submit']
This finds an `input` element with `id='submit'` and `type='submit'`.

How do you combine multiple conditions in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can combine multiple conditions in XPath using `and` or `or` operators. Example:
//input[@type='text' and @name='username']
This selects an `input` element that has both `type='text'` and `name='username'`.

How do you use or and and operators in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
In XPath, `and` and `or` operators are used to combine multiple conditions. Example:
//input[@type='text' and @name='username']
This will select an `input` element with both `type='text'` and `name='username'`. Example with `or`:
//input[@type='text' or @type='password']
This will select an `input` element with either `type='text'` or `type='password'`.

How do you handle spaces in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
In XPath, you can handle spaces in element attributes or text by enclosing the value in single or double quotes. Example:
//div[@class='example class']
This finds a `div` with a `class` attribute containing spaces.

How do you find the nth element in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To find the nth element in XPath, use the `position()` function or the `[]` indexing. Example:
(//div)[3]
This will select the 3rd `div` element in the document.

What is the not() function in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `not()` function in XPath is used to negate a condition. Example:
//input[not(@type='text')]
This will select `input` elements whose `type` is not 'text'.

How do you select elements with a specific attribute value in CSS selectors?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can select elements with a specific attribute value in CSS selectors using `[attribute='value']`. Example:
input[type='text']
This will select all `input` elements where the `type` is 'text'.

How do you locate elements by index in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can locate elements by index in XPath using the `[]` operator. Example:
(//div)[2]
This will select the second `div` element in the document.

How do you use pseudo-classes in CSS selectors?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Pseudo-classes are used to select elements based on their state, such as `:hover`, `:focus`, `:nth-child()`, etc. Example:
button:hover { background-color: blue; }
This applies a blue background to a button when it is hovered over.

What is the use of child:: in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `child::` axis in XPath is used to select child elements of a specified element. Example:
//div/child::p
This will select all `p` elements that are direct children of a `div` element.

What is the self:: axis in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `self::` axis in XPath is used to select the current node itself. Example:
//div/self::div
This selects the current `div` element.

What is the following:: axis in XPath?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `following::` axis in XPath is used to select all elements that come after the current node in the document. Example:
//div/following::p
This will select all `p` elements that appear after the `div` element.

How do you locate elements with dynamic class names?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
For dynamic class names, use partial matching in CSS selectors like `*=` or `^=` to locate the element. Example:
div[class*='dynamicClass']
This will locate all `div` elements whose `class` attribute contains 'dynamicClass'.

How do you locate hidden elements in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can locate hidden elements in Selenium, but if the element is hidden by CSS (e.g., `display: none`), it won’t be interactable. To locate it:
WebElement hiddenElement = driver.findElement(By.id("hiddenId"));
You can also use JavaScript to manipulate or interact with hidden elements.

What is the use of CSS selector nth-child?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `:nth-child()` pseudo-class in CSS selects elements based on their position within a parent element. Example:
ul li:nth-child(2)
This selects the second `li` element within an `ul`.

How do you combine class names in CSS selectors?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can combine multiple class names in CSS selectors by concatenating them with no spaces. Example:
div.class1.class2
This selects all `div` elements that have both `class1` and `class2`.

How do you find sibling elements using CSS selectors?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can find sibling elements using the `+` (immediate sibling) or `~` (general sibling) combinator. Example:
div + p
This will select the first `p` element that immediately follows a `div` element.

How do you locate elements with specific text in CSS selectors?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can locate elements with specific text in CSS selectors using `:contains()` (only available in jQuery or some testing frameworks). Example:
div:contains('text')
This will select all `div` elements that contain the text 'text'.

How do you select the first element of a specific type using CSS?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can select the first element of a specific type using the `:first-of-type` pseudo-class. Example:
div:first-of-type
This selects the first `div` element in its parent container, regardless of the class or id.

What is the use of the :nth-of-type pseudo-class?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `:nth-of-type()` pseudo-class is used to select elements based on their position in a group of sibling elements of the same type. Example:
p:nth-of-type(2)
This selects the second `p` element in its parent.

How do you select an element that is the last child using CSS?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
You can use the `:last-child` pseudo-class to select the last element of its parent. Example:
div:last-child
This will select the last `div` element in its parent container.

What is the difference between :first-child and :nth-child(1) in CSS?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The `:first-child` pseudo-class selects the first child element of its parent, while `:nth-child(1)` also selects the first child, but `nth-child` can be used with any number for other positions. Example:
ul li:first-child
selects the first `li` element of a `ul`, whereas:
ul li:nth-child(1)
does the same thing, but the `nth-child` syntax allows you to select other positions (e.g., `nth-child(2)` for the second child).

How do you select elements with an exact attribute value in CSS selectors?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
To select elements with an exact attribute value, you can use the `=` operator in CSS. Example:
input[type='text']
This will select all `input` elements where the `type` attribute is exactly `text`.

What is the purpose of waits in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Waits are used in Selenium to handle synchronization issues between the execution of commands and the browser’s state, ensuring elements are available for interaction. Example:
WebDriverWait wait = new WebDriverWait(driver, 10);
This creates a wait for 10 seconds.

What are the different types of waits available in Selenium WebDriver?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
There are three types of waits in Selenium:
  • Implicit Wait: Waits for a specified time before throwing a NoSuchElementException.
  • Explicit Wait: Waits for a certain condition to be met before proceeding.
  • Fluent Wait: A more flexible wait that allows setting polling frequency and maximum wait time.

What is an implicit wait in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
An implicit wait in Selenium is used to tell the WebDriver to wait for a specified amount of time when searching for elements if they are not immediately available. Example:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
This waits for up to 10 seconds before throwing an exception if an element is not found.

How do you implement an implicit wait in Selenium?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
Implicit wait can be implemented by calling `implicitlyWait` on the driver. Example:
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
This sets the implicit wait for 15 seconds.

What is the default timeout for an implicit wait?

Role: SDET | Tech: Selenium WebDriver | Company: General | Type: Technical
The default timeout for an implicit wait is 0 seconds. If you don't set an implicit wait, Selenium will try to find an element without waiting.

What is an explicit wait in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

An explicit wait is a type of wait where the execution is paused until a certain condition is met or a maximum time has passed.
It allows you to wait for a specific element or condition to occur, such as an element to be visible or clickable.
      

How do you implement an explicit wait in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
      

What is the WebDriverWait class in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait is a class in Selenium that provides an explicit wait mechanism.
It allows you to wait for a specific condition to occur before proceeding with the test execution.
WebDriverWait extends the FluentWait class.
      

What is a Fluent Wait in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Fluent Wait is a class in Selenium that provides a more flexible form of waiting, with customizable timeout, polling frequency, and conditions.
It waits for an element to meet a specified condition within a given time, checking the condition at regular intervals.
      

How do you implement a Fluent Wait in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

FluentWait wait = new FluentWait(driver)
    .withTimeout(Duration.ofSeconds(30))
    .pollingEvery(Duration.ofSeconds(5))
    .ignoring(NoSuchElementException.class);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("elementId")));
      

What is the purpose of until() in Fluent Wait?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

The `until()` method in Fluent Wait is used to define the condition that needs to be met before continuing with the test execution.
It continuously checks for the condition at the specified polling frequency until the timeout expires.
      

What is the ExpectedConditions class in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

The `ExpectedConditions` class in Selenium contains predefined conditions that are commonly used with explicit waits.
These include conditions like visibility of elements, element to be clickable, alert presence, etc.
      

What is the difference between implicit and explicit waits?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

- Implicit Wait is applied globally and will wait for a specified time before throwing a `NoSuchElementException` when an element is not found.
- Explicit Wait is applied to specific elements and will wait for a certain condition to occur before proceeding.
      

How do you wait for an element to be clickable in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("elementId")));
      

How do you wait for an element to be visible in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
      

How do you wait for an element to be invisible in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("elementId")));
      

How do you wait for an alert to be present in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
      

How do you wait for a page to load in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(driver -> ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete"));
      

How do you handle synchronization issues in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Synchronization issues can be handled using different types of waits, such as implicit wait, explicit wait, or fluent wait, depending on the use case. 
- Implicit Wait: Applied globally for all elements.
- Explicit Wait: Used for specific elements with conditions.
- Fluent Wait: Allows customizing polling intervals and maximum timeout.
      

How do you wait for an element to be enabled in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("elementId")));
      

How do you wait for a text to be present in an element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("elementId"), "Expected Text"));
      

What is polling in Fluent Wait?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Polling in Fluent Wait refers to the interval at which the condition is checked. The default polling interval is 500 milliseconds, but it can be changed by using the pollingEvery() method.
      

How do you change the polling interval in Fluent Wait?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

FluentWait wait = new FluentWait(driver)
    .pollingEvery(Duration.ofSeconds(2));
      

How do you wait for an element’s attribute to change in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(driver -> driver.findElement(By.id("elementId")).getAttribute("attributeName").equals("expectedValue"));
      

How do you use Fluent Wait for dynamic page loading in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

FluentWait wait = new FluentWait(driver)
    .withTimeout(Duration.ofSeconds(30))
    .pollingEvery(Duration.ofSeconds(5))
    .until(driver -> driver.findElement(By.id("elementId")).isDisplayed());
      

What is the default polling interval in Selenium's Fluent Wait?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

The default polling interval in Selenium's Fluent Wait is 500 milliseconds. This means that Fluent Wait will check for the condition every 500ms until the timeout is reached or the condition is met.
      

How do you wait for a condition in Selenium without blocking?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

You can use implicit or explicit waits to avoid blocking. With WebDriverWait, you can wait for specific conditions (e.g., visibility, clickability) and the test will continue once the condition is met.
Example:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
      

What is the use of ignoring() method in Fluent Wait?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

The `ignoring()` method in Fluent Wait allows you to specify which exceptions should be ignored during the wait time. This can be useful for exceptions like `NoSuchElementException` where you want to ignore the exception while waiting for the condition to be met.
Example:
FluentWait wait = new FluentWait(driver)
    .withTimeout(Duration.ofSeconds(30))
    .pollingEvery(Duration.ofSeconds(5))
    .ignoring(NoSuchElementException.class);
      

How do you implement multiple expected conditions in a wait?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

You can combine multiple expected conditions using `ExpectedConditions.and()` or `ExpectedConditions.or()` to create a complex condition. For example, waiting for an element to be both visible and clickable:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.and(
    ExpectedConditions.visibilityOfElementLocated(By.id("elementId")),
    ExpectedConditions.elementToBeClickable(By.id("elementId"))
));
      

How do you wait for an element to become stale in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

To wait for an element to become stale (when an element is no longer attached to the DOM), you can use the `ExpectedConditions.stalenessOf()` method.
Example:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = driver.findElement(By.id("elementId"));
wait.until(ExpectedConditions.stalenessOf(element));
      

How do you handle elements that take a long time to appear in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

For elements that take a long time to appear, you can implement explicit waits with increased timeout values or use Fluent Wait to set polling intervals and timeouts that suit your needs.
Example:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
      

What is the impact of using too many explicit waits in Selenium tests?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Using too many explicit waits can slow down the test execution, especially if the timeouts are set too high. It can also lead to unnecessary delays and a less efficient test suite.
It’s better to use waits only when necessary and optimize the waiting times according to the application’s behavior.
      

What is the purpose of a sleep method in Selenium tests?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

The `sleep()` method is used to pause the execution for a fixed amount of time. It is not recommended to use it excessively in Selenium tests, as it makes tests less efficient and can introduce unnecessary delays.
Example:
Thread.sleep(2000); // Pauses for 2 seconds
      

Why should you avoid using the Thread.sleep() method in Selenium tests?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

`Thread.sleep()` is a static wait method that pauses execution for a fixed amount of time. It is generally inefficient because it doesn’t wait for conditions to be met. 
You should avoid using it in favor of dynamic waits like implicit, explicit, or Fluent Waits, which improve test efficiency by waiting only as long as necessary.
      

What are the common challenges with waits in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Common challenges with waits in Selenium include:
- Deciding the appropriate timeout for waits.
- Using too many explicit waits leading to slower test execution.
- Incorrectly using `Thread.sleep()` which causes unnecessary delays.
- Synchronization issues when elements take varying times to appear.
To handle these, dynamic waits like implicit, explicit, or Fluent Waits should be used to optimize efficiency.
      

How do you troubleshoot wait-related issues in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

- Use browser dev tools to inspect element load timing.
- Add debug logs to trace timing and failures.
- Use try-catch to print stack traces of failures.
- Check network/API delays that may affect element rendering.
- Use screenshots to verify actual page state on failure.
      

What is the best practice for implementing waits in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

- Prefer explicit waits over implicit or static waits.
- Avoid Thread.sleep() unless absolutely necessary.
- Use WebDriverWait for specific elements/conditions.
- Use FluentWait for complex polling and exception handling.
- Keep wait times minimal and optimized for performance.
      

How do you prevent flaky tests due to timing issues in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

- Use explicit waits for dynamic elements.
- Wait for elements to be visible/clickable, not just present.
- Use stable locators, avoid auto-generated attributes.
- Optimize application loading before testing.
- Run tests on consistent environments to reduce variability.
      

How do you handle intermittent failures caused by page load timeouts?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

- Set pageLoadTimeout using driver.manage().timeouts().
- Use try-catch to retry on timeout exceptions.
- Analyze slow-loading components or network delays.
- Ensure test environments are not overloaded or throttled.
Example:
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));
      

What is the timeout period for an explicit wait?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

The timeout period for an explicit wait is defined by the user.
Example:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
This will wait up to 10 seconds for the condition to be true.
      

Can you use multiple waits at the same time in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Yes, but it is not recommended to mix implicit and explicit waits as they can lead to unpredictable wait times.
Prefer using explicit or Fluent waits based on test needs.
      

What is the difference between WebDriverWait and FluentWait?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

- WebDriverWait is a specialization of FluentWait with default polling (500ms).
- FluentWait allows more customization like polling interval, exceptions to ignore.
WebDriverWait internally uses FluentWait.
      

What happens if the element is found before the wait timeout?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

If the condition is satisfied before timeout, Selenium proceeds immediately.
The remaining wait time is ignored, improving efficiency.
      

How does WebDriver handle waits internally?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriver polls the DOM at defined intervals (e.g., every 500ms) until the condition is met or timeout occurs.
If the element is found, it proceeds; else, it throws a timeout exception.
      

What is the consequence of setting a long implicit wait timeout?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Setting a long implicit wait causes every findElement() call to wait unnecessarily long if an element is not found.
It can slow down tests and make debugging harder.
Prefer shorter implicit waits with targeted explicit waits.
      

How does an implicit wait affect the entire test?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

An implicit wait is applied globally and affects all findElement() or findElements() calls.
If an element is not found, it waits for the defined timeout before throwing an exception.

Example:
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

Can explicit waits be applied to specific elements in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Yes, explicit waits are ideal for waiting for specific elements or conditions.

Example:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));

How do you wait for multiple elements to be present on a page?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Use ExpectedConditions.presenceOfAllElementsLocatedBy() with WebDriverWait.

Example:
List<WebElement> elements = wait.until(
  ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("list-item"))
);

How do you debug wait-related issues in Selenium tests?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

- Use logging to print timestamps and actions.
- Capture screenshots on failures.
- Use breakpoints to step through waits.
- Check dev tools to confirm element loading behavior.
- Add temporary Thread.sleep() to isolate timing issues.

How do you interact with input fields in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement input = driver.findElement(By.id("name"));
input.sendKeys("John Doe");

How do you clear the contents of a text field in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement input = driver.findElement(By.id("email"));
input.clear();

How do you select a value from a dropdown in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Select dropdown = new Select(driver.findElement(By.id("country")));
dropdown.selectByVisibleText("India");
// Other options: selectByIndex(index), selectByValue("value")

How do you check whether an element is enabled in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement btn = driver.findElement(By.id("submit"));
boolean isEnabled = btn.isEnabled();

How do you check whether an element is displayed in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement label = driver.findElement(By.id("status"));
boolean isVisible = label.isDisplayed();

How do you check whether a checkbox is selected in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement checkbox = driver.findElement(By.id("terms"));
boolean isChecked = checkbox.isSelected();

How do you check the attribute of a web element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement input = driver.findElement(By.id("username"));
String placeholder = input.getAttribute("placeholder");

How do you submit a form in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement form = driver.findElement(By.id("loginForm"));
form.submit();

How do you handle radio buttons in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement maleRadio = driver.findElement(By.id("genderMale"));
if (!maleRadio.isSelected()) {
    maleRadio.click();
}

How do you interact with links in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement link = driver.findElement(By.linkText("Contact Us"));
link.click();

How do you interact with images in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement img = driver.findElement(By.tagName("img"));
String src = img.getAttribute("src");
img.click(); // if image is clickable

How do you interact with tables in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement table = driver.findElement(By.id("userTable"));
List<WebElement> rows = table.findElements(By.tagName("tr"));
for (WebElement row : rows) {
    List<WebElement> cols = row.findElements(By.tagName("td"));
    for (WebElement col : cols) {
        System.out.println(col.getText());
    }
}

How do you get the text of a web element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement label = driver.findElement(By.id("welcomeMsg"));
String text = label.getText();

How do you get the tag name of an element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement element = driver.findElement(By.id("submitBtn"));
String tagName = element.getTagName();

How do you get the value of a hidden element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement hiddenInput = driver.findElement(By.id("hiddenField"));
String value = hiddenInput.getAttribute("value");

How do you handle disabled elements in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement input = driver.findElement(By.id("disabledInput"));
boolean isDisabled = !input.isEnabled(); // true if element is disabled

How do you select multiple options from a multi-select dropdown in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Select multiSelect = new Select(driver.findElement(By.id("fruits")));
multiSelect.selectByVisibleText("Apple");
multiSelect.selectByVisibleText("Banana");

How do you deselect options in a multi-select dropdown in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Select multiSelect = new Select(driver.findElement(By.id("fruits")));
multiSelect.deselectByVisibleText("Banana");
// or deselect all
multiSelect.deselectAll();

How do you get the size of an element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement element = driver.findElement(By.id("logo"));
Dimension size = element.getSize();
System.out.println("Width: " + size.getWidth() + ", Height: " + size.getHeight());

How do you get the location of an element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement element = driver.findElement(By.id("logo"));
Point point = element.getLocation();
System.out.println("X: " + point.getX() + ", Y: " + point.getY());

How do you check if an element is clickable in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("submit")));

How do you simulate a double-click in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Actions actions = new Actions(driver);
WebElement button = driver.findElement(By.id("doubleClickBtn"));
actions.doubleClick(button).perform();

How do you right-click on an element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Actions actions = new Actions(driver);
WebElement element = driver.findElement(By.id("contextMenu"));
actions.contextClick(element).perform();

How do you simulate keyboard actions in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Actions actions = new Actions(driver);
actions.sendKeys(Keys.ENTER).perform();

How do you use the Actions class to perform a series of actions?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.id("menu")))
       .click()
       .sendKeys("text")
       .build()
       .perform();

How do you perform keyboard shortcuts using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL)
       .sendKeys("a")
       .keyUp(Keys.CONTROL)
       .perform();

How do you handle file uploads using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// HTML input element should be of type 'file'
WebElement upload = driver.findElement(By.id("upload"));
upload.sendKeys("C:\\path\\to\\file.txt");

How do you handle file downloads in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// File downloads are handled via browser profile
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", "C:\\Downloads");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");

FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);

WebDriver driver = new FirefoxDriver(options);
driver.get("https://example.com/download");

How do you handle hidden elements using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement hidden = driver.findElement(By.id("hiddenField"));
String value = hidden.getAttribute("value");
System.out.println("Hidden Value: " + value);

How do you interact with dynamically loaded elements in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
WebElement dynamicElement = wait.until(
    ExpectedConditions.visibilityOfElementLocated(By.id("dynamicContent"))
);
dynamicElement.click();

How do you refresh a web page in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

driver.navigate().refresh();

How do you get the current URL of a web page in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

String currentUrl = driver.getCurrentUrl();
System.out.println("Current URL: " + currentUrl);

How do you get the title of a web page in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

String title = driver.getTitle();
System.out.println("Page Title: " + title);

How do you check the color of an element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement element = driver.findElement(By.id("submitBtn"));
String color = element.getCssValue("color");
System.out.println("Color: " + color);

How do you check the font of an element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement element = driver.findElement(By.id("header"));
String font = element.getCssValue("font-family");
System.out.println("Font: " + font);

How do you handle images with dynamic URLs in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Match image using partial src
WebElement image = driver.findElement(By.cssSelector("img[src*='profile_pic']"));
System.out.println("Image src: " + image.getAttribute("src"));

How do you click on a link that opens in a new tab using Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Click link that opens in a new tab
driver.findElement(By.LINK_TEXT, "Open New Tab").click();
// Switch to the new tab
List tabs = new ArrayList<>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));
System.out.println(driver.getTitle());

How do you check if an element is present in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

List elements = driver.findElements(By.ID, "myElement");
if (!elements.isEmpty()) {
    System.out.println("Element is present");
} else {
    System.out.println("Element is not present");
}

How do you simulate a long press in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Actions actions = new Actions(driver);
WebElement target = driver.findElement(By.ID, "longPressElement");
actions.clickAndHold(target)
       .pause(Duration.ofSeconds(3))
       .release()
       .perform();

How do you interact with scrollable elements in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement scrollable = driver.findElement(By.ID, "scrollableDiv");
((JavascriptExecutor)driver).executeScript(
    "arguments[0].scrollTop = arguments[0].scrollHeight;", scrollable);

How do you get the text from a tooltip in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement tooltip = driver.findElement(By.ID, "tooltipElement");
String text = tooltip.getAttribute("title");
System.out.println("Tooltip text: " + text);

How do you get the list of all options in a dropdown using Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Select dropdown = new Select(driver.findElement(By.ID, "mySelect"));
for (WebElement opt : dropdown.getOptions()) {
    System.out.println(opt.getText());
}

How do you handle elements that appear only after scrolling in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement element = driver.findElement(By.ID, "lazyElement");
((JavascriptExecutor)driver).executeScript(
    "arguments[0].scrollIntoView(true);", element);
element.click();

How do you switch between tabs in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

List tabs = new ArrayList<>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(1)); // switch to second tab

How do you check if an element is read-only in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement input = driver.findElement(By.ID, "readonlyInput");
boolean isReadOnly = input.getAttribute("readonly") != null;
System.out.println("Read-only: " + isReadOnly);

How do you check if a checkbox is unchecked in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement checkbox = driver.findElement(By.ID, "agreeCheckbox");
if (!checkbox.isSelected()) {
    System.out.println("Checkbox is unchecked");
}

How do you simulate mouse movements in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Actions actions = new Actions(driver);
WebElement target = driver.findElement(By.id("moveTarget"));
actions.moveToElement(target).perform();

How do you check if an element is overlapping another element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Get positions and sizes
Rectangle r1 = driver.findElement(By.id("elem1")).getRect();
Rectangle r2 = driver.findElement(By.id("elem2")).getRect();
boolean overlaps = 
    r1.x < r2.x + r2.width &&
    r1.x + r1.width > r2.x &&
    r1.y < r2.y + r2.height &&
    r1.y + r1.height > r2.y;
System.out.println("Overlapping: " + overlaps);

How do you get the parent element of a given element in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebElement child = driver.findElement(By.id("childElem"));
WebElement parent = child.findElement(By.xpath(".."));

How do you handle elements with changing IDs in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use stable attributes or relative XPath
WebElement elem = driver.findElement(
    By.xpath("//button[contains(@id,'submit_')]")
);

How do you handle drop-downs in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Select dropdown = new Select(driver.findElement(By.id("mySelect")));
dropdown.selectByVisibleText("Option Text");
// Or selectByValue / selectByIndex

How do you handle frames and iframes in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch to frame by id or index
driver.switchTo().frame("frameName");
// Or
driver.switchTo().frame(0);
// After actions, switch back
driver.switchTo().defaultContent();

How do you handle mouse hover actions in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Actions actions = new Actions(driver);
WebElement menu = driver.findElement(By.id("menu"));
actions.moveToElement(menu).perform();

What is the Actions class in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// The Actions class allows complex user gestures
Actions actions = new Actions(driver);
actions.click(element)
       .sendKeys("text")
       .build()
       .perform();

How do you perform drag and drop in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

Actions actions = new Actions(driver);
WebElement src = driver.findElement(By.id("source"));
WebElement tgt = driver.findElement(By.id("target"));
actions.dragAndDrop(src, tgt).perform();

How do you handle AJAX elements in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
WebElement element = wait.until(
    ExpectedConditions.visibilityOfElementLocated(By.id("ajaxElement"))
);

How do you read text from a web page in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Locate element and use getText()
WebElement element = driver.findElement(By.id("textElement"));
String text = element.getText();
System.out.println("Text: " + text);

How do you perform scrolling in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Scroll by pixel
((JavascriptExecutor)driver).executeScript("window.scrollBy(0,500);");
// Scroll to element
WebElement elem = driver.findElement(By.id("footer"));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", elem);

What is the difference between sendKeys() and clear() methods?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// sendKeys() types text into an input field
driver.findElement(By.id("input")).sendKeys("text");
// clear() removes existing text
driver.findElement(By.id("input")).clear();

What is the use of the executeScript() method in WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// executeScript() runs JavaScript in browser context
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('btn').click();");

How do you handle JavaScript alerts in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch to alert and accept
Alert alert = driver.switchTo().alert();
alert.accept();

How do you handle confirmation boxes in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Dismiss confirmation box
Alert confirm = driver.switchTo().alert();
confirm.dismiss();

How do you handle prompt boxes in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Send text to prompt and accept
Alert prompt = driver.switchTo().alert();
prompt.sendKeys("input text");
prompt.accept();

How do you handle authentication pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Embed credentials in URL
driver.get("https://username:password@example.com");

How do you handle file download pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Configure browser preferences for automatic download
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
WebDriver driver = new FirefoxDriver(options);

How do you switch to an alert in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch context to alert
Alert alert = driver.switchTo().alert();

How do you accept an alert in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch to the alert and accept it
Alert alert = driver.switchTo().alert();
alert.accept();

How do you dismiss an alert in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: TCS | Type: Technical

// Switch to the alert and dismiss it
Alert alert = driver.switchTo().alert();
alert.dismiss();

How do you get the text of an alert in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Wipro | Type: Technical

// Switch to the alert and retrieve its text
Alert alert = driver.switchTo().alert();
String text = alert.getText();
System.out.println("Alert text: " + text);

How do you handle multiple windows in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Infosys | Type: Technical

// Store the current window handle
String mainWindow = driver.getWindowHandle();

// Iterate through all windows
for (String handle : driver.getWindowHandles()) {
    driver.switchTo().window(handle);
    System.out.println("Switched to: " + driver.getTitle());
}

// Switch back to main window
driver.switchTo().window(mainWindow);

How do you close a specific window in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Capgemini | Type: Technical

// Switch to the target window and close it
String targetHandle = /* handle of window to close */;
driver.switchTo().window(targetHandle);
driver.close();

// Switch back to main window if needed
driver.switchTo().window(/* main handle */);

How do you handle pop-ups in a new tab using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Cognizant | Type: Technical

// Click link to open pop-up in new tab
driver.findElement(By.LINK_TEXT, "Open Pop-up").click();

// Switch to new tab
List tabs = new ArrayList<>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));

// Handle pop-up alert
driver.switchTo().alert().accept();

// Close pop-up tab and switch back
driver.close();
driver.switchTo().window(tabs.get(0));

What is the purpose of getWindowHandles() in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Returns a set of window handles for all open windows/tabs
Set handles = driver.getWindowHandles();

How do you handle browser notifications in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Accenture | Type: Technical

// Disable notifications via ChromeOptions
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
WebDriver driver = new ChromeDriver(options);

How do you handle permission pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Tech Mahindra | Type: Technical

// For Chrome, use prefs to auto-allow geolocation
Map prefs = new HashMap<>();
prefs.put("profile.default_content_setting_values.geolocation", 1);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);

How do you automate closing of browser pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Try to accept alert, catch if none
try {
    Alert alert = driver.switchTo().alert();
    alert.accept();
} catch (NoAlertPresentException e) {
    // No alert to close
}

How do you handle pop-ups in headless browser mode?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Even headless, alerts work the same
WebDriver driver = new ChromeDriver(new ChromeOptions().setHeadless(true));
driver.get("https://example.com");
driver.switchTo().alert().accept();

How do you maximize the browser window in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: TCS | Type: Technical

// Maximize window
driver.manage().window().maximize();

How do you get the dimensions of a browser window in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Wipro | Type: Technical

// Get window size
Dimension size = driver.manage().window().getSize();
System.out.println("Width: " + size.getWidth() + ", Height: " + size.getHeight());

How do you handle pop-ups in mobile browser testing?

Role: SDET | Tech: Selenium | Company: Capgemini | Type: Technical

// For mobile emulation
ChromeOptions opts = new ChromeOptions();
opts.setExperimentalOption("mobileEmulation", Map.of("deviceName", "Pixel 2"));
WebDriver driver = new ChromeDriver(opts);
driver.switchTo().alert().accept();

How do you capture a screenshot of a pop-up in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch to alert -> cannot screenshot alert directly, use full page
File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File("popup.png"));

How do you handle modal windows in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Infosys | Type: Technical

// Modal is part of DOM
WebElement modal = driver.findElement(By.id("myModal"));
modal.findElement(By.cssSelector(".close")).click();

How do you handle frames within a pop-up in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch into pop-up frame
driver.switchTo().frame("popupFrame");
// interact...
driver.switchTo().defaultContent();

How do you verify the title of a pop-up window in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Cognizant | Type: Technical

// After switch
String title = driver.getTitle();
System.out.println("Popup Title: " + title);

How do you handle dynamic pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Tech Mahindra | Type: Technical

// Wait for pop-up element dynamically
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement popup = wait.until(
  ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".dynamic-popup"))
);
popup.findElement(By.cssSelector(".close")).click();

How do you close all pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Loop through alerts
try {
  while (true) {
    driver.switchTo().alert().accept();
  }
} catch (NoAlertPresentException e) {
  // none left
}

How do you handle pop-ups that appear after a delay in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Wait for alert to appear, then accept
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.accept();

How do you capture the text from a pop-up in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch to alert and get its text
Alert alert = driver.switchTo().alert();
String text = alert.getText();
System.out.println("Pop-up Text: " + text);

How do you handle pop-ups during form submissions in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Submit form then handle pop-up
driver.findElement(By.id("myForm")).submit();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.accept();

How do you bypass pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Disable browser pop-ups via options (Chrome example)
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-popup-blocking");
WebDriver driver = new ChromeDriver(options);

How do you handle unexpected pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Try to accept if present, ignore if not
try {
    Alert alert = driver.switchTo().alert();
    alert.accept();
} catch (NoAlertPresentException e) {
    // No pop-up appeared
}

How do you test pop-up blockers using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Configure Chrome to enable pop-up blocking
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", List.of("disable-popup-blocking"));
WebDriver driver = new ChromeDriver(options);
// Trigger pop-up and verify no alert present
driver.findElement(By.id("triggerPopup")).click();
assertThrows(NoAlertPresentException.class, 
    () -> driver.switchTo().alert());

How do you verify the presence of a pop-up in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Check alert presence using wait
try {
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
    wait.until(ExpectedConditions.alertIsPresent());
    System.out.println("Pop-up is present");
} catch (TimeoutException e) {
    System.out.println("No pop-up detected");
}

How do you handle pop-ups during file upload in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Upload file then accept any pop-up
driver.findElement(By.id("fileUpload")).sendKeys("/path/to/file");
Alert alert = new WebDriverWait(driver, Duration.ofSeconds(5))
    .until(ExpectedConditions.alertIsPresent());
alert.accept();

How do you handle pop-ups in different browser tabs?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch to tab with pop-up
List tabs = new ArrayList<>(driver.getWindowHandles());
for (String tab : tabs) {
    driver.switchTo().window(tab);
    try {
        driver.switchTo().alert().accept();
        break;
    } catch (NoAlertPresentException ignored) {}
}
// Return to original tab if needed
driver.switchTo().window(tabs.get(0));

How do you interact with elements behind a pop-up in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Dismiss pop-up then interact normally
Alert alert = driver.switchTo().alert();
alert.accept();
driver.findElement(By.id("underlyingElement")).click();

How do you disable pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Disable pop-ups via browser options (Chrome example)
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-popup-blocking");
WebDriver driver = new ChromeDriver(options);

How do you handle pop-ups in incognito mode using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Wipro | Type: Technical

// Launch Chrome in incognito and disable pop-ups
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito", "--disable-popup-blocking");
WebDriver driver = new ChromeDriver(options);

How do you automate filling out forms within pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Accenture | Type: Technical

// Switch to popup frame or window, then fill form fields
driver.switchTo().frame("popupFrame");
driver.findElement(By.id("name")).sendKeys("John Doe");
driver.findElement(By.id("email")).sendKeys("john@example.com");
driver.findElement(By.id("submit")).click();
driver.switchTo().defaultContent();

How do you click elements inside a pop-up in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch to popup context then click element
driver.switchTo().window(popupHandle);
driver.findElement(By.cssSelector(".popup-button")).click();
driver.switchTo().window(mainHandle);

How do you simulate keyboard actions within pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch to popup, then use Actions for keyboard
driver.switchTo().alert(); // or frame/window
Actions actions = new Actions(driver);
actions.sendKeys(Keys.TAB).sendKeys("text").sendKeys(Keys.ENTER).perform();

How do you handle scrollable pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: Capgemini | Type: Technical

// Switch to popup frame and scroll content
driver.switchTo().frame("popupFrame");
WebElement scrollable = driver.findElement(By.cssSelector(".popup-content"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollTop=arguments[0].scrollHeight;", scrollable);

How do you assert the presence of a pop-up in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use explicit wait for alert or popup element
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
boolean present = false;
try {
  wait.until(ExpectedConditions.alertIsPresent());
  present = true;
} catch (TimeoutException e) {}
System.out.println("Pop-up present: " + present);

How do you interact with pop-ups in a browser window using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch to popup window handle then actions
String popup = driver.getWindowHandles().stream().filter(h -> !h.equals(main)).findFirst().get();
driver.switchTo().window(popup);
driver.findElement(By.id("popupAction")).click();
driver.switchTo().window(main);

How do you handle alert boxes with dynamic content in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Wait and read dynamic alert text
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
String dynamicText = alert.getText();
// Validate or handle accordingly
alert.accept();

How do you handle nested pop-ups in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Handle first popup
Alert first = new WebDriverWait(driver, Duration.ofSeconds(5)).until(
  ExpectedConditions.alertIsPresent());
first.accept();
// Handle nested popup
Alert second = new WebDriverWait(driver, Duration.ofSeconds(5)).until(
  ExpectedConditions.alertIsPresent());
second.accept();

How do you verify the content of a pop-up in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Wait for alert, get its text and assert
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
String text = alert.getText();
assertEquals("Expected Message", text);
alert.accept();

What is Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Selenium Grid is a tool that allows you to run Selenium tests in parallel on multiple machines and browsers, distributed across different environments.

What is the purpose of Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
The purpose of Selenium Grid is to speed up test execution by running tests in parallel across different browser–OS combinations, and to centralize test management via a Hub–Node architecture.

How do you set up Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
1. Download Selenium server jar.
2. Start the Hub: java -jar selenium-server.jar hub.
3. Start Nodes connecting to the Hub: java -jar selenium-server.jar node --hub http://localhost:4444.
4. Verify registration in the Grid console.

What is a Hub in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
The Hub is the central server that receives test requests and routes them to appropriate Nodes based on browser/OS capabilities.

What is a Node in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
A Node is a machine (local or remote) registered with the Hub that executes the WebDriver tests using the browser and platform it’s configured with.

How do you register nodes in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Nodes register by starting the Selenium server with the --role node --hub http://hub-host:4444 options and any desired --browser capabilities.

What are the advantages of using Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
- Parallel test execution
- Cross-browser and cross-platform testing
- Centralized test management
- Resource optimization

How do you perform parallel testing in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Configure your test framework (TestNG/JUnit) with multiple <test> or @Parameters and point each to a different RemoteWebDriver session on the Hub.

What is the role of the Hub in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
The Hub’s role is to receive test requests, match them to available Nodes based on desired capabilities, and dispatch the tests accordingly.

How do you configure multiple nodes in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Start each node with its own JSON config or CLI flags pointing to the same Hub URL. For example:
java -jar selenium-server.jar node --hub http://hub:4444 --port 5555 --role node
Repeat on different machines or ports.

How do you specify the browser version for a node in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
In the node configuration JSON or CLI, set the browserVersion capability. Example JSON snippet:
{
  "capabilities": [{
    "browserName": "chrome",
    "browserVersion": "95.0",
    "maxInstances": 5
  }]
}

How do you specify the operating system for a node in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
In the node’s JSON config, include the platformName capability. For example:
{
  "capabilities": [{
    "browserName": "firefox",
    "platformName": "WINDOWS",
    "maxInstances": 3
  }]
}

What are the limitations of Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
  • Scalability overhead — requires infrastructure to maintain nodes.
  • Network latency can slow tests.
  • Debugging remote failures is more complex.
  • Limited to browser-based testing only.

How do you run tests on multiple browsers using Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Define multiple DesiredCapabilities (one per browser) in your test suite and point each to the Grid’s Hub URL via RemoteWebDriver. Tests will be dispatched to matching nodes.

How do you run tests on multiple operating systems using Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Configure nodes on different OS machines with appropriate platformName. In tests, set DesiredCapabilities.platformName to target each OS, then execute in parallel.

What are the challenges of running tests in parallel?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
  • Shared state conflicts (test isolation).
  • Resource contention (CPU, memory).
  • Synchronization issues with test data.
  • Difficulties in logging and debugging concurrent runs.

How do you handle synchronization issues in parallel testing?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Use explicit waits (WebDriverWait) for element conditions, avoid shared mutable state, and isolate test data for each thread or session.

What is the role of DesiredCapabilities in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
DesiredCapabilities defines the browser, version, and platform for a test session. The Grid Hub matches these capabilities to appropriate nodes.

How do you handle session management in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Ensure each RemoteWebDriver instance is created with a unique session. Close sessions after use with driver.quit() to free up nodes for new tests.

How do you ensure that the right test cases are run on the right nodes in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual

// Define DesiredCapabilities for each test to match node capabilities.
// Example: For Chrome on Windows:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName("chrome");
caps.setPlatform(Platform.WINDOWS);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://hub:4444"), caps);

How do you view the status of nodes in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Open the Grid console in a browser at http://hub-host:4444/grid/console. It lists all registered nodes, their capabilities, and current sessions.

How do you troubleshoot issues with Selenium Grid nodes?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
  • Check node logs for errors.
  • Verify network connectivity to the Hub.
  • Ensure browser drivers on node match the desired browser versions.
  • Restart the node process if stale or unregistered.

How do you set a timeout for a node in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Use the –timeout (client timeout) and –maxSession parameters when starting the node:
java -jar selenium-server.jar node --hub http://hub:4444 --timeout 60 --maxSession 5

How do you specify the maximum number of sessions for a node in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Set the maxSession flag in the node’s config JSON or CLI:
java -jar selenium-server.jar node --hub http://hub:4444 --maxSession 4

How do you run tests on a remote machine using Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: Infosys | Type: Conceptual
Point your RemoteWebDriver to the Hub’s URL, and ensure the remote node is registered with matching capabilities:
WebDriver driver = new RemoteWebDriver(
  new URL("http://hub:4444"), caps);

How do you use a headless browser in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: Capgemini | Type: Conceptual
Configure node capabilities for headless mode:
ChromeOptions opts = new ChromeOptions();
opts.addArguments("--headless");
caps.setCapability(ChromeOptions.CAPABILITY, opts);

How do you run tests in different browsers using Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Create separate DesiredCapabilities for each browser (Chrome, Firefox, etc.) and dispatch parallel RemoteWebDriver instances to the Hub.

What are the limitations of running tests in parallel using Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
  • Increased resource usage on nodes.
  • Flakiness due to race conditions.
  • Complex test data and environment isolation.
  • Longer setup time for grid infrastructure.

How do you use Docker with Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Use the official Docker images:
docker run -d -p 4444:4444 --name selenium-hub selenium/hub
docker run -d --link selenium-hub:hub selenium/node-chrome
docker run -d --link selenium-hub:hub selenium/node-firefox

How do you ensure that tests are thread-safe in parallel execution?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual

// Ensure no shared mutable state:
// 1. Use thread-local WebDriver instances.
// 2. Isolate test data per thread.
// 3. Avoid static variables for test data or page objects.

What is the impact of running tests in parallel on test stability?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual

// Parallel execution can expose race conditions and shared-state issues,
// leading to flaky tests. Proper isolation and synchronization are critical
// to maintain stability.

How do you handle flaky tests in parallel execution?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual

// 1. Add explicit waits for dynamic elements.
// 2. Retries on failure via test framework.
// 3. Stabilize locators and test data.
// 4. Log and analyze flakiness patterns.

How do you configure browser-specific capabilities in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual

// Example for Chrome:
ChromeOptions chromeOpts = new ChromeOptions();
chromeOpts.setCapability("platformName", "WINDOWS");
chromeOpts.setBrowserVersion("95.0");
RemoteWebDriver driver = new RemoteWebDriver(new URL(hubUrl), chromeOpts);

How do you run tests on multiple machines using Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual

// 1. Start Hub on one machine.
// 2. Register Nodes on each remote machine pointing to the Hub.
// 3. Execute tests via RemoteWebDriver targeting the Hub URL.

How do you monitor resource usage in Selenium Grid nodes?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual

// Use monitoring tools like:
// - JConsole to connect to node JVM.
// - System metrics (CPU, memory) via Prometheus/Grafana.
// - Inspect node logs for session metrics.

How do you debug issues with Selenium Grid Hub?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual

// 1. Enable debug logging on Hub startup.
// 2. Check Hub console at /grid/console.
// 3. Review Hub logs for registration and dispatch errors.
// 4. Verify network accessibility from Nodes.

What is the default timeout for a node in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual

// Default node timeout is 30 seconds (session idle timeout).
// Can be overridden via --timeout CLI or JSON config.

How do you configure a node to run specific tests in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual

// Use node tags or custom capability, e.g.:
caps.setCapability("role", "regression");
  
// On Node JSON:
"capabilities": [{
  "role": "regression",
  ...
}]

// Then match tests via DesiredCapabilities role="regression"

How do you balance the load between nodes in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual

// 1. Configure maxSession per node based on capacity.
// 2. Use ring topology or smart distribution (Grid 4).
// 3. Monitor and adjust node capabilities dynamically.

What is the maximum number of sessions a node can handle in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
The maximum number of sessions is controlled by the maxSession parameter on the node. You can set it to any integer value in the node’s JSON config or via CLI.

How do you configure Selenium Grid to run tests on mobile devices?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Register Appium nodes for mobile devices to the Hub. In node config, specify appiumVersion, platformName, and device capabilities. Tests then use RemoteWebDriver pointing to the Hub with mobile DesiredCapabilities.

How do you run tests on multiple devices using Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Start multiple Appium node instances (one per device) registered to the same Hub. In your test suite, launch parallel RemoteWebDriver sessions with each device’s udid and platformName in the capabilities.

How do you configure a custom browser in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
In the node’s JSON config, add a custom capabilities entry with browserName set to your custom browser identifier and point seleniumAddress to the binary driver path. Then register the node with that config.

How do you handle different screen resolutions in Selenium Grid?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Specify screenResolution capability in the node config’s moz:firefoxOptions or use chromeOptions args like --window-size=1280,800. Tests will then run in that resolution.

How do you ensure tests are isolated in parallel execution?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Use thread-local WebDriver instances, unique test data per thread, and avoid shared static state. Clean up cookies and local storage between tests to maintain isolation.

How do you manage test data in parallel testing?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Provision independent data sets for each parallel thread—e.g., use a data provider that supplies unique inputs or isolate each test’s database transactions in setup/teardown methods.

How do you handle browser-specific issues in parallel execution?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Tag tests with browser names and apply conditional logic or separate capability sets. Use explicit browser-specific waits or driver options to handle quirks per browser.

How do you verify the execution order of tests in parallel execution?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Rely on your test framework’s reporting (TestNG/JUnit) which logs thread names and timestamps. You can also instrument each test to write start/end logs to ensure the order.

How do you analyze test results in parallel execution?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
Aggregate reports from your test runner (e.g., TestNG XML, JUnit HTML) and use a dashboard or CI tool that merges parallel results, showing pass/fail per thread and time metrics.

How do you optimize test execution time in parallel testing?

Role: SDET | Tech: Selenium Grid | Company: General | Type: Conceptual
- Distribute tests evenly across nodes based on capacity.
- Reduce unnecessary waits and use explicit waits wisely.
- Parallelize only independent test suites.
- Use data-driven tests to minimize code duplication.
- Cache setup/teardown steps when possible.

What is TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Conceptual
TestNG is a testing framework inspired by JUnit and NUnit, designed to simplify a broad range of testing needs, from unit to end-to-end testing.

What are the features of TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Conceptual
- Annotations for flexible configuration.
- Supports data-driven testing via @DataProvider.
- Parallel test execution.
- Test grouping and dependencies.
- Built-in reporting and logging.
- Configuration methods: @BeforeSuite, @AfterMethod, etc.

How do you integrate TestNG with Selenium?

Role: SDET | Tech: Selenium & TestNG | Company: General | Type: Technical
Add the TestNG dependency in your build (Maven/Gradle), create test classes with TestNG annotations, and use RemoteWebDriver or WebDriver instances in @BeforeMethod setup methods.

How do you create a TestNG test case?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Annotate a public method with @Test. Example:

import org.testng.annotations.Test;

public class LoginTest {
  @Test
  public void validLogin() {
    // WebDriver setup
    driver.get("https://example.com/login");
    // perform login steps
  }
}

What is the purpose of the @Test annotation in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
The @Test annotation marks a method as a test method to be executed by TestNG.

How do you group test cases in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use the groups attribute on @Test and include in XML or via include in suite file. Example:

@Test(groups = {"smoke", "login"})
public void validLogin() { ... }

How do you run multiple test cases in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Include multiple @Test methods in your class or list multiple classes in the TestNG XML suite file.

How do you create a test suite in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Create a testng.xml file:



  
    
      
      
    
  

How do you run a test suite in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Execute via your IDE’s TestNG runner or use Maven:

mvn test -DsuiteXmlFile=testng.xml

What is the purpose of the @BeforeMethod annotation in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
The @BeforeMethod annotation marks a method to run before each @Test method in the current class. Use it to initialize WebDriver, open browsers, or set up test data.

What is the purpose of the @AfterMethod annotation in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
The @AfterMethod annotation marks a method to run after each @Test method in the current class. Use it to clean up resources, close browsers, or reset test data.

How do you handle test dependencies in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use the dependsOnMethods attribute of @Test to specify method dependencies. Example:

@Test
public void login() { … }

@Test(dependsOnMethods = "login")
public void purchase() { … }

What is the purpose of the @BeforeClass annotation in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
The @BeforeClass annotation marks a method to run once before any test methods in the current class. Use it for class-level setup, such as initializing shared resources.

What is the purpose of the @AfterClass annotation in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
The @AfterClass annotation marks a method to run once after all test methods in the current class have run. Use it for class-level teardown, such as releasing shared resources.

How do you skip a test case in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
You can disable a test with enabled = false, or throw a SkipException. Examples:

@Test(enabled = false)
public void skippedTest() { … }

// or

@Test
public void conditionallySkip() {
  throw new SkipException("Skipping this test");
}

How do you run failed test cases in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
After a test run, TestNG generates a testng-failed.xml file in the test-output folder. Execute this XML to rerun only the failed tests.

How do you create a data-driven test in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use the @DataProvider annotation to supply test data and link it with the dataProvider attribute of @Test. Example:

@DataProvider(name = "users")
public Object[][] getUsers() {
  return new Object[][] {{"user1","pass1"}, {"user2","pass2"}};
}

@Test(dataProvider = "users")
public void loginTest(String user, String pwd) {
  // use user, pwd
}

What is the purpose of the @DataProvider annotation in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
The @DataProvider annotation marks a method that returns an array of test data. It enables data-driven testing by feeding multiple parameter sets into a single @Test method.

How do you run tests in parallel using TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Configure parallelism in the testng.xml file or via annotation attributes. Example testng.xml settings:


  
  

How do you generate reports in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
TestNG automatically generates HTML and XML reports in the test-output folder. For custom reports, implement the IReporter interface or use third-party listeners (e.g., ReportNG, Allure).

What is the purpose of the @BeforeTest annotation in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
The @BeforeTest annotation marks a method to run before any test methods inside the <test> tag in the XML suite. Use it for test-group setup (e.g., setting up test data or configurations).

What is the purpose of the @AfterTest annotation in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
The @AfterTest annotation marks a method to run after all test methods inside the <test> tag have executed. Use it for cleanup tasks related to that test group (e.g., closing connections).

How do you prioritize test cases in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use the priority attribute of @Test. Lower values run first.

How do you handle exceptions in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use the expectedExceptions attribute in @Test to mark a test as passed if it throws the specified exception.

How do you create a custom listener in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Implement one of TestNG’s listener interfaces (e.g., ITestListener) and register it via the @Listeners annotation or in testng.xml.

How do you create a custom reporter in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Implement the IReporter interface, override the generateReport method, and register your class in testng.xml:

What is the purpose of the @BeforeSuite annotation in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
The @BeforeSuite annotation marks a method to run once before all tests in the entire suite. Use it for global setup, such as initializing shared services or reporting frameworks.

What is the purpose of the @AfterSuite annotation in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
The @AfterSuite annotation marks a method to run once after all tests in the entire suite have completed. Use it for global teardown, such as closing databases or generating final reports.

How do you run test cases with multiple data sets in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use a @DataProvider method that returns multiple parameter sets, and link it in your @Test using the dataProvider attribute.

How do you assert test results in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use TestNG’s built-in assertion methods from org.testng.Assert to verify expected vs. actual outcomes.

// Example assertions
Assert.assertTrue(isVisible, "Element should be visible");
Assert.assertEquals(actualTitle, "Home", "Title mismatch");

What is the assertTrue() method in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
assertTrue() checks that a boolean condition is true. If not, the test fails with an optional message.

// Usage
boolean loggedIn = loginPage.isLoggedIn();
Assert.assertTrue(loggedIn, "User should be logged in");

What is the assertEquals() method in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
assertEquals() compares expected and actual values. It supports primitives, objects, arrays, with an optional message.

// Usage for Strings
String title = driver.getTitle();
Assert.assertEquals(title, "Dashboard", "Page title incorrect");

How do you handle soft assertions in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use the SoftAssert class to collect failures and assert all at the end.

SoftAssert soft = new SoftAssert();
soft.assertTrue(cond1, "Condition1 failed");
soft.assertEquals(val, expectedVal, "Value mismatch");
// ...
soft.assertAll();  // triggers assertion errors for all failures

How do you create a dependency between test cases in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use the dependsOnMethods or dependsOnGroups attribute of @Test.

@Test
public void login() { ... }

@Test(dependsOnMethods = "login")
public void checkout() { ... }

How do you run test cases conditionally in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Throw a SkipException in the test or use enabled=false. Example:

@Test
public void conditionalTest() {
  if (!condition) {
    throw new SkipException("Skipping this test");
  }
  // test logic
}

How do you use annotations in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
TestNG provides annotations like @BeforeSuite, @BeforeClass, @BeforeMethod, @Test, @AfterMethod, @AfterClass, and @AfterSuite to control setup/teardown and test execution order.

How do you handle multiple test suites in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Create multiple testng.xml files and invoke them via your build tool or IDE. You can also nest <suite-files> in a master suite.



  
    
    
  

How do you rerun failed test cases in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use the generated testng-failed.xml in test-output. Configure your CI to execute it automatically or manually run:

mvn test -DsuiteXmlFile=test-output/testng-failed.xml

How do you handle timeout for test cases in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use the timeOut attribute on @Test. Example:

@Test(timeOut = 5000) // 5 seconds
public void slowTest() throws InterruptedException {
  Thread.sleep(6000);
}

How do you run test cases in a specific order in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use the `priority` attribute on the `@Test` annotation. Lower priority values run first.

@Test(priority = 1)
public void firstTest() { … }

@Test(priority = 2)
public void secondTest() { … }

How do you execute a test case multiple times in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Use the `invocationCount` attribute on the `@Test` annotation.

@Test(invocationCount = 5)
public void repeatTest() {
  // this runs 5 times
}

How do you pass parameters to test cases in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Define `` entries in `testng.xml` and use `@Parameters` annotation.




@Test
@Parameters("url")
public void testWithParam(String url) {
  driver.get(url);
}

How do you generate an XML report in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
TestNG automatically creates `testng-results.xml` in the `test-output` folder after execution. No extra config is needed.

How do you generate a JUnit report in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Enable JUnit report generation via `` in `testng.xml`:


  

How do you create a listener for logging in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Implement `ITestListener` and override methods for logging, then register via `@Listeners` or `testng.xml`.

public class LogListener implements ITestListener {
  @Override
  public void onTestSuccess(ITestResult result) {
    System.out.println("PASS: " + result.getName());
  }
}
// Register:
@Listeners(LogListener.class)
public class Tests { … }

How do you generate a test report in HTML using TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
TestNG auto-generates `index.html` and other HTML reports in `test-output`. For custom HTML, implement `IReporter`.

How do you integrate TestNG with Jenkins?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
1. Configure Maven/Gradle to run TestNG.
2. Add “Publish TestNG Results” post-build action in Jenkins and point to `**/test-output/*.xml`.

How do you handle retry logic in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Implement `IRetryAnalyzer` and reference in `@Test` annotation:

public class Retry implements IRetryAnalyzer {
  private int count = 0;
  public boolean retry(ITestResult result) {
    return count++ < 2; // retry twice
  }
}

@Test(retryAnalyzer = Retry.class)
public void flakyTest() { … }

How do you execute test cases in batches in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical
Split tests into multiple `` tags in `testng.xml` and run them as separate builds or configure parallel execution at suite level with `parallel="tests"`.


  
  

How do you create a dependent test case in TestNG?

Role: SDET | Tech: TestNG | Company: General | Type: Technical

@Test
public void loginTest() {
    // login steps
}

@Test(dependsOnMethods = "loginTest")
public void purchaseTest() {
    // purchase steps after login
}

How do you perform browser zooming in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use JavaScript to set zoom level
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.body.style.zoom='80%'");

How do you handle browser console logs in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Capture console logs (Chrome)
LogEntries logs = driver.manage().logs().get(LogType.BROWSER);
for (LogEntry entry : logs) {
    System.out.println(entry.getLevel() + " " + entry.getMessage());
}

How do you capture network traffic using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use BrowserMob Proxy with Selenium
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
ChromeOptions options = new ChromeOptions().setProxy(seleniumProxy);
WebDriver driver = new ChromeDriver(options);
proxy.newHar("network");
driver.get("https://example.com");
Har har = proxy.getHar();
// process har entries

How do you handle HTTPS certificate issues in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Ignore certificate errors (Chrome)
ChromeOptions options = new ChromeOptions()
    .setAcceptInsecureCerts(true);
WebDriver driver = new ChromeDriver(options);

How do you simulate browser back and forward buttons in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Navigate back
driver.navigate().back();
// Navigate forward
driver.navigate().forward();

How do you handle browser caching in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Clear cache via JavaScript
((JavascriptExecutor) driver).executeScript("window.localStorage.clear();");
((JavascriptExecutor) driver).executeScript("window.sessionStorage.clear();");
// Or use browser profile preferences

How do you inject custom JavaScript in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Execute arbitrary JavaScript
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("alert('Injected!');");

How do you integrate Selenium with Cucumber for BDD testing?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Maven dependencies for cucumber-java and cucumber-junit
// Step definitions use Selenium WebDriver
public class Steps {
  WebDriver driver;
  @Given("I open the browser")
  public void openBrowser() {
    driver = new ChromeDriver();
  }
  @When("I go to {string}")
  public void goTo(String url) {
    driver.get(url);
  }
}

How do you test responsive web designs using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Emulate device viewport sizes
driver.manage().window().setSize(new Dimension(375, 667)); // iPhone X
driver.get("https://responsive-site.com");
// verify layout changes

How do you handle shadow DOM elements in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use JavaScript Executor to pierce Shadow DOM
WebElement host = driver.findElement(By.cssSelector("shadow-host-selector"));
WebElement shadowRoot = (WebElement)((JavascriptExecutor)driver)
    .executeScript("return arguments[0].shadowRoot", host);
WebElement innerElem = shadowRoot.findElement(By.cssSelector("inner-selector"));
innerElem.click();

How do you integrate Selenium with Appium for mobile app testing?

Role: SDET | Tech: Appium/Selenium | Company: General | Type: Technical

// Use Appium Java client with DesiredCapabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "Android");
caps.setCapability("appPackage", "com.example.app");
caps.setCapability("appActivity", ".MainActivity");
URL appiumServer = new URL("http://localhost:4723/wd/hub");
AndroidDriver driver = new AndroidDriver<>(appiumServer, caps);
// Then use Selenium calls on driver

How do you perform visual regression testing with Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Capture baseline screenshots and compare
File baseline = new File("baseline/home.png");
File current = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
BufferedImage imgBaseline = ImageIO.read(baseline);
BufferedImage imgCurrent = ImageIO.read(current);
// Use pixel-by-pixel comparison or a library like AShot
ImageDiff diff = new AShot().takeScreenshot(driver).getImageDiff();
assertFalse(diff.hasDiff(), "Visual regression detected");

How do you test single-page applications (SPAs) using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use explicit waits for SPA route changes
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
driver.get("https://example-spa.com");
driver.findElement(By.linkText("Load Data")).click();
wait.until(driver1 -> ((JavascriptExecutor)driver1)
    .executeScript("return window.location.hash").equals("#/data"));
WebElement dataElem = driver.findElement(By.id("data-item"));
assertTrue(dataElem.isDisplayed());

How do you handle shadow DOM elements in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// See Q1 for JavaScript Executor approach to access shadowRoot

How do you automate testing for canvas-based elements in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Canvas interactions via JavaScript
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript(
  "var canvas = document.querySelector('canvas');" +
  "var ctx = canvas.getContext('2d');"
);
// Or use Actions to click specific coordinates
new Actions(driver).moveByOffset(x, y).click().perform();

How do you simulate touch gestures (e.g., swipe, tap) in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use TouchActions for mobile emulation
TouchAction touch = new TouchAction<>(driver);
touch.press(point(startX, startY))
     .waitAction(waitOptions(Duration.ofMillis(500)))
     .moveTo(point(endX, endY))
     .release()
     .perform();

How do you test WebGL-based applications using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Verify canvas presence and rendering state
WebElement canvas = driver.findElement(By.tagName("canvas"));
assertTrue(canvas.isDisplayed());
// Use JS to check WebGL context
Boolean glPresent = (Boolean)((JavascriptExecutor)driver)
    .executeScript(
      "return !!document.querySelector('canvas').getContext('webgl')");
assertTrue(glPresent, "WebGL context not available");

How do you test browser extensions using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Set up WebDriver to include the browser extension
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("path_to_extension.crx"));
WebDriver driver = new ChromeDriver(options);
// Now interact with the browser extension through Selenium commands
driver.get("chrome://extensions/");

How do you handle testing in a containerized environment (e.g., Kubernetes) with Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use Docker containers with Selenium Grid for parallel execution
// Deploy Hub and Node containers using Docker-compose or Kubernetes
docker-compose -f selenium-grid.yml up -d
// Ensure the container has access to the web application you want to test
WebDriver driver = new RemoteWebDriver(new URL("http://:4444/wd/hub"), capabilities);
// Run the tests on the containers

How do you configure Selenium WebDriver to test in private browsing mode?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use options to enable incognito mode
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
WebDriver driver = new ChromeDriver(options);
// The driver will now open Chrome in incognito mode

How do you simulate low-bandwidth network conditions in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use Chrome DevTools Protocol for network throttling
Map params = new HashMap<>();
params.put("downloadThroughput", 500000);  // 500kbps
params.put("uploadThroughput", 500000);    // 500kbps
driver.executeCdpCommand("Network.emulateNetworkConditions", params);
// This will throttle the network speed during the test

How do you automate testing of real-time chat applications using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Automate interactions with chat input and message elements
WebDriver driver = new ChromeDriver();
driver.get("chatapp_url");
// Interact with chat input
WebElement chatInput = driver.findElement(By.id("chat-input"));
chatInput.sendKeys("Hello");
chatInput.submit();
// Validate if the message appears in the chat
WebElement message = driver.findElement(By.xpath("//div[@class='message' and contains(text(), 'Hello')]"));
assertTrue(message.isDisplayed());

How do you handle testing of OAuth-based authentication flows in Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use the WebDriver to automate login page navigation and credentials input
driver.get("https://example.com/oauth-login");
// Input username and password
driver.findElement(By.id("username")).sendKeys("test_user");
driver.findElement(By.id("password")).sendKeys("password123");
// Submit login form
driver.findElement(By.id("submit")).click();
// Capture redirection after OAuth login and validate
String currentUrl = driver.getCurrentUrl();
assertTrue(currentUrl.contains("redirect_uri"));

How do you validate client-side JavaScript errors using Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use logging from the browser's console to capture JavaScript errors
LoggingPreferences logs = new LoggingPreferences();
logs.enable(LogEntries.Type.BROWSER, Level.ALL);
ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.LOGGING_PREFS, logs);
WebDriver driver = new ChromeDriver(options);
driver.get("https://example.com");
// After actions, check for JavaScript errors in the console
LogEntries logEntries = driver.manage().logs().get(LogEntries.Type.BROWSER);
for (LogEntry entry : logEntries) {
    if (entry.getLevel().equals(Level.SEVERE)) {
        System.out.println(entry.getMessage());
    }
}

How do you perform cross-browser testing with cloud platforms (e.g., BrowserStack, Sauce Labs) using Selenium?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Use remote WebDriver with cloud platform capabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("chrome");
capabilities.setVersion("latest");
capabilities.setPlatform(Platform.WINDOWS);
URL remoteUrl = new URL("https://username:accessKey@hub-cloud.browsertack.com/wd/hub");
WebDriver driver = new RemoteWebDriver(remoteUrl, capabilities);
// Now interact with the browser through Selenium commands

How do you automate testing of multi-language web applications in Selenium WebDriver?

Role: SDET | Tech: Selenium | Company: General | Type: Technical

// Switch languages by changing language settings on the app or page
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");
// Change the language to Spanish, for example
WebElement languageSelector = driver.findElement(By.id("language-selector"));
languageSelector.click();
WebElement spanishOption = driver.findElement(By.xpath("//option[@value='es']"));
spanishOption.click();
// Verify text in Spanish
WebElement header = driver.findElement(By.id("header"));
assertEquals(header.getText(), "Bienvenido");