skip to content

Selenium

The WebDriver stack that drives real browsers over an HTTP protocol, from five language bindings, with Grid for distributed runs. Interviewers ask because long-lived suites still run on it.

on this pageshow

explore

questions

265 · 10 sections

Where does Selenium Manager store the drivers it downloads, and does every Selenium 4 run download again?

level: juniorimportance: must knowfreq 56%
basics
~20 s

In a per-user cache folder, by default ~/.cache/selenium, and no. Selenium 4's Selenium Manager reuses a matching cached driver on later runs and downloads only when the cache has no suitable copy. SE_CACHE_PATH moves the folder.

open as a page

In Selenium 4, what happens when you construct a ChromeDriver without configuring any chromedriver path?

level: juniorimportance: must knowfreq 74%
basics
~20 s

Selenium Manager runs automatically. The binary bundled in the Selenium 4 client detects the installed Chrome, works out the matching chromedriver, downloads it if the local cache lacks it, and returns the path, so the session starts with no PATH entry and no setup code.

open as a page

In Selenium 4, what does setting the `webSocketUrl` capability to true on a new session do?

level: juniorimportance: must knowfreq 64%
basics
~20 s

It asks the remote end to open a WebDriver BiDi socket for that session. If the remote end supports BiDi, the capabilities it returns contain webSocketUrl again, this time as the ws:// address the client connects to.

open as a page

In Selenium 4, what actually happens when a Java test calls new ChromeDriver()?

level: juniorimportance: must knowfreq 85%
basics
~20 s

Constructing ChromeDriver starts a local driver process, waits for it to listen on a free loopback port, then sends it a new-session request. The driver launches the browser and replies with a session id that every later command carries.

open as a page

In Selenium 4, how does a client choose between a configured driver executable and Selenium Manager?

level: middleimportance: must knowfreq 55%
basics
~20 s

An explicitly configured executable wins. If a driver path is set on the service builder or through the webdriver.chrome.driver system property, the Selenium 4 client launches that file; only when nothing is configured does it hand resolution to the bundled Selenium Manager.

open as a page

In Selenium, why does By.cssSelector fail on an element inside a web component's shadow tree?

level: juniorimportance: must knowfreq 68%
basics
~20 s

The find command searches one node tree from a single start node, and a shadow tree is a separate tree, so a descendant selector never reaches inside. Find the host, take its shadow root, search again from there.

open as a page

In Selenium, what does each driver.findElement call cost when a test loops over many rows?

level: juniorimportance: must knowfreq 66%
basics
~20 s

Each findElement call is one HTTP command to the browser driver, sent as POST /session/{id}/element. A loop over 300 rows sends 300 separate commands, and those round trips add up no matter how simple the selector is.

open as a page

In Selenium, why can a CSS locator never match an element by its visible text?

level: middleimportance: must knowfreq 72%
basics
~20 s

Because a CSS selector matches on tags, ids, classes, attributes, structural position and state, never on the characters inside an element. Selenium sends the string straight to the browser's querySelectorAll, so a locator gets exactly that power and no more.

open as a page

In Selenium 4, what geometric rule does RelativeLocator's above() apply, and why do overlapping elements match no direction?

level: middleimportance: must knowfreq 62%
basics
~20 s

Selenium compares bounding rectangles edge to edge: a candidate is above an anchor only when the candidate's bottom edge sits at or higher than the anchor's top edge. Any overlap fails all four directional tests.

open as a page

In Selenium, which two checks does ExpectedConditions.elementToBeClickable actually perform before returning?

level: juniorimportance: must knowfreq 74%
basics
~10 s

Just two: isDisplayed and isEnabled. Selenium's elementToBeClickable locates the element, confirms the browser renders it and that it is not disabled, then returns it. Nothing in the condition asks whether something covers it.

open as a page

In Selenium's Java bindings, what does the FluentWait class let a test configure about a wait?

level: juniorimportance: must knowfreq 62%
basics
~10 s

FluentWait is Selenium's configurable wait. withTimeout sets how long it keeps trying, pollingEvery sets the gap between tries, ignoring and ignoreAll list exception types to swallow and retry, and withMessage sets the timeout text.

open as a page

In Selenium, what happens if you set an implicit wait and also use WebDriverWait in the same session?

level: juniorimportance: must knowfreq 76%
basics
~10 s

Wait times become unpredictable. Selenium's documentation warns against mixing the two, and gives the example of a 10-second implicit wait with a 15-second explicit wait producing a timeout after 20 seconds.

open as a page

In Selenium, how does ExpectedConditions.stalenessOf decide that the element it was given is gone?

level: middleimportance: must knowfreq 53%
basics
~20 s

By calling a method on the reference each poll and watching for it to fail. Selenium 4 calls isEnabled and discards the result; when that raises a stale element reference or no such element error, the condition returns true.

open as a page

In Selenium's ExpectedConditions, which helpers hand back a usable WebElement and which only hand back a Boolean?

level: middleimportance: must knowfreq 61%
basics
~20 s

Helpers that ask for a node return it: presenceOfElementLocated, visibilityOfElementLocated, visibilityOf and elementToBeClickable give a WebElement, the all-elements helpers give a list, alertIsPresent gives an Alert. Helpers that assert a page fact, such as invisibilityOfElementLocated, stalenessOf and titleIs, give only a Boolean.

open as a page

In Selenium, which class performs a hover or a right-click, and what call actually runs it?

level: juniorimportance: must knowfreq 76%
basics
~10 s

Selenium's Actions class builds them: moveToElement for a hover, contextClick for a right-click, plus doubleClick, clickAndHold, release and dragAndDrop. Nothing reaches the browser until you call perform() on the chain.

open as a page

In Selenium, what does ElementClickInterceptedException mean, and what does its message name?

level: juniorimportance: must knowfreq 74%
basics
~20 s

The click target is covered: another element sits over its centre point and would receive the click. The driver's message names that intercepting element, usually its opening tag with id and class, so read it.

open as a page

In Selenium, how does the string given to JavascriptExecutor.executeScript run, and how do you get a value back?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Selenium runs the string as the body of an anonymous function in the current frame, so you need an explicit return to get a value; without one you get null. Values passed after the script appear as arguments[0], arguments[1].

open as a page

In Selenium, which three methods does the Select class offer to choose an option, and what does each match?

level: juniorimportance: must knowfreq 82%
basics
~10 s

Selenium's Select class offers selectByVisibleText, which matches an option's rendered text; selectByValue, which matches its value attribute exactly; and selectByIndex, which matches its zero-based position. Each throws NoSuchElementException when nothing matches.

open as a page

In Selenium, which Java types may be passed to executeScript, and what types can its result be?

level: middleimportance: must knowfreq 62%
basics
~20 s

You may pass numbers, booleans, strings, WebElements, and lists or String-keyed maps of those; anything else throws IllegalArgumentException. Results come back as Boolean, Long, Double, String, List, Map, WebElement or null, and always need a cast.

open as a page

In Selenium, how do you read a JavaScript confirm dialog's text and then accept or cancel it?

level: juniorimportance: must knowfreq 78%
basics
~10 s

Take the dialog with driver.switchTo().alert(), which returns an Alert. Call getText() for its message, then accept() to press OK or dismiss() to press Cancel. Use sendKeys only on a prompt, before accepting it.

open as a page

In Selenium, which Chrome preferences make a download land in a directory your test picked, with no save prompt?

level: juniorimportance: must knowfreq 74%
basics
~20 s

Set the Chrome preference download.default_directory to an absolute path and download.prompt_for_download to false, passed as the prefs experimental option on ChromeOptions. The browser then writes the file into that folder on whichever machine runs the browser.

open as a page

In Selenium, what is the difference between driver.get(url) and driver.navigate().to(url)?

level: juniorimportance: must knowfreq 78%
basics
~10 s

Nothing functional separates them. Both send the same WebDriver Navigate To command and load the URL in the current tab. navigate() exists because the object it returns also carries back, forward and refresh.

open as a page

A Selenium test fails with UnhandledAlertException and the confirm dialog is gone by the time you look. Why?

level: seniorimportance: must knowfreq 52%
basics
~10 s

Selenium 4 sessions default to the dismiss and notify prompt handler, so the remote end dismissed the dialog and then failed that command with UnhandledAlertException. Nothing lost the dialog; the default answered it.

open as a page

A Selenium suite calls addCookie before navigating and every test throws InvalidCookieDomainException — why, and what is the fix?

level: seniorimportance: must knowfreq 70%
basics
~20 s

WebDriver can only set a cookie for the document the browser currently holds. A fresh session sits on a blank page with no host, so there is nothing for the cookie to belong to and addCookie rejects it. Navigate to the target origin first.

open as a page

In Selenium 4, what does Take Element Screenshot return when the element is taller than the viewport?

level: middleimportance: must knowfreq 61%
basics
~20 s

Only the visible part. Take Element Screenshot scrolls the element into view and then paints from the viewport framebuffer, so an element taller than the window comes back clipped at the viewport edge, never stitched.

open as a page

A Selenium suite reads browser console entries on Chrome but the same code throws on Firefox. Why, and how do you handle it?

level: seniorimportance: must knowfreq 62%
basics
~10 s

Log retrieval was never standardised in W3C WebDriver, so Selenium routes it to its own extension endpoint. ChromeDriver implements that endpoint and geckodriver does not, so the call throws UnsupportedCommandException on Firefox.

open as a page

In Selenium, why does a failure hook's element screenshot throw StaleElementReferenceException, and how do you make the capture safe?

level: seniorimportance: must knowfreq 43%
basics
~20 s

Element references die with the node they point at. Take Element Screenshot resolves the reference before it paints, so a hook capturing after the page re-rendered gets a stale element reference instead of an image.

open as a page

In Selenium 4, how do you capture a whole-page image in Firefox, and what changes when the session is remote?

level: seniorimportance: must knowfreq 52%
basics
~20 s

Firefox exposes getFullPageScreenshotAs through the HasFullPageScreenshot interface, backed by a Mozilla extension endpoint rather than a standard command. Over a remote session the object is a RemoteWebDriver, so you must wrap it with Augmenter before the cast succeeds.

open as a page

In Selenium's Java client, how do you read a page's browser console output, and what comes back?

level: juniorimportance: should knowfreq 58%
basics
~10 s

Call driver.manage().logs().get(LogType.BROWSER). It returns a LogEntries collection of LogEntry objects, each carrying a level, a timestamp in epoch milliseconds, and the message text. Each call drains the buffer it read.

open as a page

In Selenium, what does a component-scoped page object hold so its lookups stay inside one widget?

level: juniorimportance: must knowfreq 66%
basics
~10 s

It holds the widget's root element. WebElement implements SearchContext, so the class searches through that root on every lookup and can never match a node that lives outside the widget it models.

open as a page

In Selenium's @FindBy annotation, what is the difference between the shorthand attributes and the how/using pair?

level: juniorimportance: must knowfreq 74%
basics
~10 s

There is no behavioural difference for the everyday strategies: @FindBy(id = "x") and @FindBy(how = How.ID, using = "x") build the same By. The pair exists for How.ID_OR_NAME, which has no shorthand attribute.

open as a page

In Selenium's PageFactory, what changes when you pass a WebElement to initElements instead of the driver?

level: middleimportance: must knowfreq 58%
basics
~20 s

Every proxied field is then located through that element instead of the whole document. PageFactory wraps whatever context you pass in a DefaultElementLocatorFactory, so each lookup starts at that element rather than at the page root.

open as a page

In Selenium's PageFactory, how do @FindBys and @FindAll differ when they annotate the same page-object field?

level: middleimportance: must knowfreq 62%
basics
~10 s

@FindBys builds a ByChained: each locator is searched inside the elements the previous one matched. @FindAll builds a ByAll: every locator runs against the same context and the matches are merged into one union.

open as a page

In Selenium's PageFactory, how do you bind a List<WebElement> field, and what happens to a field left unannotated?

level: juniorimportance: should knowfreq 47%
basics
~20 s

A list field takes the same @FindBy and is resolved with findElements, but the annotation is required or the field stays null. An unannotated WebElement field is bound using its own name as an id, then a name.

open as a page

In Selenium's Docker images, why is --shm-size=2g recommended for browser containers?

level: juniorimportance: must knowfreq 66%
basics
~20 s

Browsers put rendered content in the shared-memory filesystem /dev/shm, and Selenium's image docs say Chrome crashes on the small 64 MB allocation a container gets by default. Passing --shm-size=2g, or shm_size: 2gb in compose, gives it room.

open as a page

In Selenium Grid, what is the difference between the hub role and the node role?

level: juniorimportance: must knowfreq 82%
basics
~20 s

The hub is the grid's single entry point: it takes session requests from test clients and hosts the event bus that nodes register on. A node owns a machine's browsers and runs the sessions the hub places on it.

open as a page

In Selenium Grid 4, what does the /status endpoint return and what does its ready flag mean?

level: juniorimportance: must knowfreq 66%
basics
~20 s

Selenium Grid's /status returns JSON holding a boolean ready flag, a message, and a nodes array describing every registered node and its slots. Ready is true only when at least one node is up and has a free slot.

open as a page

In Selenium 4, how do you point a test at a Grid endpoint instead of starting a local browser?

level: juniorimportance: must knowfreq 76%
basics
~20 s

Build a RemoteWebDriver with two arguments: the Grid's URL and an options object such as ChromeOptions. Those options become the session request the Grid routes, and every line of test code after that is unchanged.

open as a page

In Selenium Grid, what does a Node's --max-sessions flag default to, and what silently caps it?

level: middleimportance: must knowfreq 60%
basics
~20 s

A Selenium 4 Node's --max-sessions defaults to the number of processors its JVM reports. Selenium clamps any higher value back to that number unless --override-max-sessions true is passed, and a Node never runs more sessions than it declared slots.

open as a page

In Selenium, can two test threads safely share a single WebDriver instance?

level: juniorimportance: must knowfreq 76%
basics
~10 s

No. A Selenium WebDriver object carries no thread-safety guarantee, and one session drives one browser, so two threads issuing commands through it interleave into a single confused conversation. Give every thread its own driver.

open as a page

In a Selenium suite, how does a ThreadLocal<WebDriver> holder work, and why must teardown call remove()?

level: middleimportance: must knowfreq 74%
basics
~20 s

A ThreadLocal holder stores one WebDriver per thread, so each parallel test gets its own browser session. Teardown must quit the driver and call remove, or the entry survives on a reused pool thread and the next test inherits it.

open as a page

A Selenium suite is green at two workers and flaky at six on one host - how do you tell a per-worker collision from memory pressure?

level: seniorimportance: must knowfreq 65%
basics
~20 s

A collision fails early and asymmetrically: the first worker survives and the rest die at session start or read each other's files. Memory pressure fails late and everywhere, worsens smoothly with worker count, and kills browsers mid-test.

open as a page

In a parallel Selenium run, cases throw NoSuchWindowException and failure screenshots show another test's page. What is the cause?

level: seniorimportance: must knowfreq 58%
basics
~10 s

Two or more threads are driving one Selenium session. Both symptoms are the same fact: every thread's command lands in one browser whose window and page another thread has already changed underneath it.

open as a page

How do you choose how many parallel Selenium browser workers a single machine should run?

level: principalimportance: must knowfreq 50%
basics
~20 s

Measure it on the real hardware; there is no formula. Each worker runs a whole browser process tree, so memory and CPU cap the count long before threads do. Ramp the workers up until per-case time degrades, then back off.

open as a page

In Selenium 4, what replaces the Selenium 3 DesiredCapabilities object when you start a local Chrome session?

level: juniorimportance: must knowfreq 78%
basics
~10 s

A browser Options object. In Selenium 4 you build ChromeOptions, FirefoxOptions or EdgeOptions and pass it to the driver constructor; DesiredCapabilities is no longer how a local session is configured.

open as a page

After upgrading to Selenium 4.6 or later, which driver-binary setup code can you delete, and why?

level: juniorimportance: must knowfreq 66%
basics
~20 s

The driver-path setup. Selenium 4.6 and later bundle Selenium Manager, which locates or downloads a matching browser driver when no driver path is set, so the webdriver.chrome.driver property and any third-party driver-manager bootstrap can be deleted.

open as a page

In Selenium 4, why can one test body drive Chrome, Firefox, Edge and Safari without a rewrite?

level: juniorimportance: must knowfreq 76%
basics
~20 s

Because every one of those browsers is automated through the same W3C WebDriver command set. Only the driver and options objects built at start-up differ; finding elements, clicking, reading text and waiting are identical calls.

open as a page

Which languages does the Selenium project itself ship client bindings for at Selenium 4?

level: juniorimportance: must knowfreq 68%
basics
~10 s

Selenium 4 ships official clients for Java, Python, C#/.NET, Ruby and JavaScript. Other languages such as PHP, R and Rust are covered by community bindings maintained outside the project, which speak the same protocol.

open as a page

In Selenium 4's JavaScript client, why must nearly every driver call be awaited?

level: middleimportance: must knowfreq 58%
basics
~20 s

Because every command returns a promise rather than a value, and Selenium 4 removed the old control flow that ordered commands for you. Without await you hold a promise, which is always truthy, so conditions silently pass.

open as a page