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 pageshowhide
explore
- WebDriver Architecture40 questions
- The HTTP Contract17 questions
- Opening and Closing Sessions16 questions
- Binary Provisioning7 questions
- Element Location32 questions
- Addressing Methods12 questions
- Query Expressions12 questions
- Structural Lookups8 questions
- Synchronization Model31 questions
- Blocking Mechanisms18 questions
- Readiness Predicates13 questions
- Element Interaction36 questions
- Core Input Commands15 questions
- Low-Level Input12 questions
- Command Failure Signals9 questions
- Browser Context Control24 questions
- Switching Targets9 questions
- Persistent Session Data8 questions
- Layout and Navigation7 questions
- Screenshots and Logs16 questions
- Visual Capture7 questions
- Diagnostic Streams9 questions
- Abstraction Layers20 questions
- The Page Factory12 questions
- Screen and Widget Models8 questions
- Grid Deployment28 questions
- Run Topologies11 questions
- Capacity and Matching10 questions
- Remote Run Mechanics7 questions
- Suite Execution16 questions
- Concurrent Session Safety10 questions
- Toolchain Seams6 questions
- Ecosystem and Positioning22 questions
- Language Bindings10 questions
- Tooling Comparisons12 questions
questions
265 · 10 sectionsWhere does Selenium Manager store the drivers it downloads, and does every Selenium 4 run download again?
basics
~20 sIn 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.
In Selenium 4, what happens when you construct a ChromeDriver without configuring any chromedriver path?
basics
~20 sSelenium 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.
In Selenium 4, what does setting the `webSocketUrl` capability to true on a new session do?
basics
~20 sIt 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.
In Selenium 4, what actually happens when a Java test calls new ChromeDriver()?
basics
~20 sConstructing 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.
In Selenium 4, how does a client choose between a configured driver executable and Selenium Manager?
basics
~20 sAn 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.
In Selenium, what does By.partialLinkText match that By.linkText does not?
basics
~10 sSubstrings. Both strategies look only at anchor elements and compare their visible text, but By.linkText needs the whole trimmed text to equal the value, while By.partialLinkText matches any anchor whose text contains it.
In Selenium, why does By.cssSelector fail on an element inside a web component's shadow tree?
basics
~20 sThe 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.
In Selenium, what does each driver.findElement call cost when a test loops over many rows?
basics
~20 sEach 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.
In Selenium, why can a CSS locator never match an element by its visible text?
basics
~20 sBecause 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.
In Selenium 4, what geometric rule does RelativeLocator's above() apply, and why do overlapping elements match no direction?
basics
~20 sSelenium 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.
In Selenium, which two checks does ExpectedConditions.elementToBeClickable actually perform before returning?
basics
~10 sJust 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.
In Selenium's Java bindings, what does the FluentWait class let a test configure about a wait?
basics
~10 sFluentWait 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.
In Selenium, what happens if you set an implicit wait and also use WebDriverWait in the same session?
basics
~10 sWait 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.
In Selenium, how does ExpectedConditions.stalenessOf decide that the element it was given is gone?
basics
~20 sBy 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.
In Selenium's ExpectedConditions, which helpers hand back a usable WebElement and which only hand back a Boolean?
basics
~20 sHelpers 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.
In Selenium, which class performs a hover or a right-click, and what call actually runs it?
basics
~10 sSelenium'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.
In Selenium, what does ElementClickInterceptedException mean, and what does its message name?
basics
~20 sThe 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.
In Selenium, how does the string given to JavascriptExecutor.executeScript run, and how do you get a value back?
basics
~20 sSelenium 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].
In Selenium, which three methods does the Select class offer to choose an option, and what does each match?
basics
~10 sSelenium'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.
In Selenium, which Java types may be passed to executeScript, and what types can its result be?
basics
~20 sYou 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.
In Selenium, how do you read a JavaScript confirm dialog's text and then accept or cancel it?
basics
~10 sTake 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.
In Selenium, which Chrome preferences make a download land in a directory your test picked, with no save prompt?
basics
~20 sSet 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.
A Selenium test fails with UnhandledAlertException and the confirm dialog is gone by the time you look. Why?
basics
~10 sSelenium 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.
A Selenium suite calls addCookie before navigating and every test throws InvalidCookieDomainException — why, and what is the fix?
basics
~20 sWebDriver 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.
In Selenium 4, what does Take Element Screenshot return when the element is taller than the viewport?
basics
~20 sOnly 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.
A Selenium suite reads browser console entries on Chrome but the same code throws on Firefox. Why, and how do you handle it?
basics
~10 sLog 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.
In Selenium, why does a failure hook's element screenshot throw StaleElementReferenceException, and how do you make the capture safe?
basics
~20 sElement 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.
In Selenium 4, how do you capture a whole-page image in Firefox, and what changes when the session is remote?
basics
~20 sFirefox 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.
In Selenium's Java client, how do you read a page's browser console output, and what comes back?
basics
~10 sCall 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.
In Selenium, what does a component-scoped page object hold so its lookups stay inside one widget?
basics
~10 sIt 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.
In Selenium's @FindBy annotation, what is the difference between the shorthand attributes and the how/using pair?
basics
~10 sThere 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.
In Selenium's PageFactory, what changes when you pass a WebElement to initElements instead of the driver?
basics
~20 sEvery 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.
In Selenium's PageFactory, how do @FindBys and @FindAll differ when they annotate the same page-object field?
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.
In Selenium's PageFactory, how do you bind a List<WebElement> field, and what happens to a field left unannotated?
basics
~20 sA 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.
In Selenium's Docker images, why is --shm-size=2g recommended for browser containers?
basics
~20 sBrowsers 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.
In Selenium Grid, what is the difference between the hub role and the node role?
basics
~20 sThe 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.
In Selenium Grid 4, what does the /status endpoint return and what does its ready flag mean?
basics
~20 sSelenium 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.
In Selenium 4, how do you point a test at a Grid endpoint instead of starting a local browser?
basics
~20 sBuild 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.
In Selenium Grid, what does a Node's --max-sessions flag default to, and what silently caps it?
basics
~20 sA 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.
In Selenium, can two test threads safely share a single WebDriver instance?
basics
~10 sNo. 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.
In a Selenium suite, how does a ThreadLocal<WebDriver> holder work, and why must teardown call remove()?
basics
~20 sA 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.
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?
basics
~20 sA 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.
How do you choose how many parallel Selenium browser workers a single machine should run?
basics
~20 sMeasure 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.
In Selenium 4, what replaces the Selenium 3 DesiredCapabilities object when you start a local Chrome session?
basics
~10 sA 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.
After upgrading to Selenium 4.6 or later, which driver-binary setup code can you delete, and why?
basics
~20 sThe 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.
In Selenium 4, why can one test body drive Chrome, Firefox, Edge and Safari without a rewrite?
basics
~20 sBecause 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.
Which languages does the Selenium project itself ship client bindings for at Selenium 4?
basics
~10 sSelenium 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.
In Selenium 4's JavaScript client, why must nearly every driver call be awaited?
basics
~20 sBecause 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.