Docsity

Selenium WebDriver Interview Questions and Answers with Java | Selenium 4, Quizzes of Education & Teaching

Toggle sidebar
bg1
SELENIUM / INTERVIEW PREPARATION
Selenium WebDriver with Java · 1
Selenium Interview Questions and
Answers
Selenium WebDriver with Java · Collected by Mohammad Taslim
Prepare for beginner and intermediate QA automation interviews. This guide covers Selenium fundamentals,
element locators, waits, browser interactions, and test design. The Java snippets use Selenium 4 syntax and
assume an active WebDriver session unless stated otherwise.
Selenium Fundamentals
01 What is Selenium?
Selenium is an open-source suite for automating web browsers. WebDriver code can be written in languages
such as Java, Python, C#, Ruby, and JavaScript. Common browser targets include Chrome, Edge, Firefox, and
Safari. The browser and operating system combination determines which driver you can use.
02 What are the main Selenium tools?
WebDriver controls browsers from test code. Selenium IDE records and replays browser interactions.
Selenium Grid routes WebDriver sessions to remote machines and supports parallel execution across browser
and platform configurations.
03 Which WebDriver implementations are commonly used?
ChromeDriver, EdgeDriver, FirefoxDriver, and SafariDriver automate their respective browsers.
RemoteWebDriver connects to a remote WebDriver endpoint, such as Selenium Grid.
04 What kinds of testing can Selenium support?
Use it to exercise browser-based workflows for functional, regression, smoke, sanity, cross-browser, and
responsive testing. It can also cover integration scenarios through the UI. Define the inputs and expected
outcomes first, then compare them with the application’s actual behavior.
05 What are Selenium’s limitations?
Selenium automates browsers. Native desktop and mobile app interfaces require other tools. Test organization,
assertions, and reporting typically come from a framework such as JUnit or TestNG. Pixel-level visual
comparison requires a separate tool.
06 How did Selenium 2 and 3 differ?
Selenium 2 introduced WebDriver to the Selenium project while retaining Selenium Remote Control (RC).
The Selenium 3 Java distribution moved the legacy RC client to a separate package. The examples in this
guide use Selenium 4.
pf3
pf4
pf5

Partial preview of the text

Download Selenium WebDriver Interview Questions and Answers with Java | Selenium 4 and more Quizzes Education & Teaching in PDF only on Docsity!

Selenium Interview Questions and

Answers

Selenium WebDriver with Java · Collected by Mohammad Taslim Prepare for beginner and intermediate QA automation interviews. This guide covers Selenium fundamentals, element locators, waits, browser interactions, and test design. The Java snippets use Selenium 4 syntax and assume an active WebDriver session unless stated otherwise.

Selenium Fundamentals

01 What is Selenium?

Selenium is an open-source suite for automating web browsers. WebDriver code can be written in languages such as Java, Python, C#, Ruby, and JavaScript. Common browser targets include Chrome, Edge, Firefox, and Safari. The browser and operating system combination determines which driver you can use.

02 What are the main Selenium tools?

WebDriver controls browsers from test code. Selenium IDE records and replays browser interactions. Selenium Grid routes WebDriver sessions to remote machines and supports parallel execution across browser and platform configurations.

03 Which WebDriver implementations are commonly used?

ChromeDriver, EdgeDriver, FirefoxDriver, and SafariDriver automate their respective browsers. RemoteWebDriver connects to a remote WebDriver endpoint, such as Selenium Grid.

04 What kinds of testing can Selenium support?

Use it to exercise browser-based workflows for functional, regression, smoke, sanity, cross-browser, and responsive testing. It can also cover integration scenarios through the UI. Define the inputs and expected outcomes first, then compare them with the application’s actual behavior.

05 What are Selenium’s limitations?

Selenium automates browsers. Native desktop and mobile app interfaces require other tools. Test organization, assertions, and reporting typically come from a framework such as JUnit or TestNG. Pixel-level visual comparison requires a separate tool.

06 How did Selenium 2 and 3 differ?

Selenium 2 introduced WebDriver to the Selenium project while retaining Selenium Remote Control (RC). The Selenium 3 Java distribution moved the legacy RC client to a separate package. The examples in this guide use Selenium 4.

Element Location

07 How do findElement and findElements differ?

findElement returns the first match and throws NoSuchElementException when there is no match. findElements returns all matches as a list, which is empty when nothing matches.

08 Which locator strategies are available in Java?

Use a stable ID or test-specific attribute when the application provides one. Link text and partial link text apply to links. A class-name locator accepts one class token at a time. By.id("email"); By.name("books"); By.linkText("Today’s Deals"); By.partialLinkText("Service"); By.tagName("button"); By.className("inputtext"); By.cssSelector("input[data-testid='email']"); By.xpath("//button[normalize-space(.)='Sign in']");

09 How do you build a CSS selector?

Use # for an ID, a period for a class, and brackets for an attribute. Combine them to narrow your match. To locate an element by its displayed text, use link text for a link or an XPath text condition. input#email input.inputtext input[name='email'] input.inputtext[name='email']

10 What is XPath and when is it useful?

XPath locates nodes in the page’s DOM. An absolute path starts at the document root and depends on the page’s structure. A search such as //button can find matching nodes anywhere in the document. Use contains() for partial matches, and combine conditions with and or or. /html/body/main/form/button //button[@type='submit'] //button[contains(normalize-space(.), 'Sign')] //input[@type='submit' or @name='btnReset'] //input[@type='submit' and @name='btnLogin']

Browser Interactions with Java

16 How do you type into a field or click a link?

Locate the element, then use sendKeys() for text entry or click() to activate a link or button. Use clear() first when the test needs to replace existing text in an editable field. driver.findElement(By.id("email")).sendKeys("[email protected]"); driver.findElement(By.linkText("Help")).click();

17 How do you scroll the page?

JavaScriptExecutor can scroll the browsing context by a specified number of pixels. A positive vertical offset scrolls down. JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("window.scrollBy(0, 600)");

18 How do you verify the page title?

Read the title with getTitle() and compare it with the expected value using an assertion from your test framework. This example uses JUnit Jupiter. assertEquals("Account Dashboard", driver.getTitle());

19 How do you hover and read a CSS property?

Use Actions.moveToElement().perform() to hover. Call getCssValue() with the CSS property name, such as font-size, to read its computed value. WebElement menu = driver.findElement(By.id("account-menu")); new Actions(driver).moveToElement(menu).perform(); String fontSize = menu.getCssValue("font-size");

20 How do you select an option from a dropdown?

Use Select for a native HTML select element. Choose by zero-based index, option value, or visible text. Each line below is an alternative. For a custom dropdown, locate and click its controls. Select books = new Select(driver.findElement(By.id("books"))); books.selectByIndex(0); books.selectByValue("fiction"); books.selectByVisibleText("The Alchemist");

21 Can you set an input value with JavaScript?

Yes. A script can assign the DOM value directly. This can skip keyboard and input events that the application expects. Use sendKeys() when the test is meant to exercise real text entry. js.executeScript("arguments[0].value = arguments[1];", driver.findElement(By.id("email")), "[email protected]");

Alerts and Test Design

22 How do you handle JavaScript alerts?

An alert displays a message. A confirmation gives the user an OK or Cancel choice. A prompt accepts text. Switch to the dialog with switchTo().alert(), then call getText(), accept(), or dismiss() as appropriate. Use sendKeys() only for a prompt. Alert prompt = driver.switchTo().alert(); String message = prompt.getText(); prompt.sendKeys("Sample response"); prompt.accept();

23 Can WebDriver handle operating system dialogs?

A native file picker sits outside the web page. For a file upload, send the file path directly to the HTML input of type file. Native dialogs that require desktop interaction need separate tooling.

24 How do you capture a screenshot?

Cast the driver to TakesScreenshot and call getScreenshotAs(). This example returns a temporary image file that your test can copy into its reporting directory. File image = ((TakesScreenshot) driver) .getScreenshotAs(OutputType.FILE);

25 What is the Page Object Model?

A page object groups the locators and actions for a page or component behind methods such as signIn(). Tests call those methods and assert expected outcomes. Keeping locators in one place makes UI changes easier to maintain.

26 How should tests handle CAPTCHA?

CAPTCHA is designed to distinguish humans from automated clients. Use approved test keys or disable the CAPTCHA in a controlled test environment when the goal is to test the surrounding workflow.

27 What is the same origin policy?

Browsers restrict how JavaScript from one origin can read data from another. An origin is defined by its scheme, host, and port. WebDriver can navigate across origins or switch to an iframe, while scripts executed in a page are still subject to the browser’s security rules.

28 What is Selenese?

Selenese is the name historically used for Selenium IDE commands. Common categories include actions that interact with the browser, accessors that read state, and checks. An assert failure stops the current test, while verify records the failure and lets the test continue.

Official Reference

Selenium documentation at selenium.dev/documentation/ covers WebDriver, Grid, and migration to Selenium

  1. The Selenium IDE command reference is at selenium.dev/selenium-ide/docs/.