Selenium Java
100+ Questions
and Answers
with Selenium 4
code
Question: What is Selenium?
Answer: suite of tools for automating web
browsers, to automate interactions and verify
expected behavior
Question: What are the Selenium components?
Answer: Selenium IDE, Selenium WebDriver, and
Selenium Grid
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is Selenium IDE?
Answer: Browser extension or add-on (Chrome,
Firefox & Edge) to record scripts, which can run on
any browser or Selenium Grid. Used for bug
reproduction scripts and website exploration.
Question: How does Selenium WebDriver work?
Answer: It interacts with a web browser or a
remote web server. It sends commands to a
browser and retrieves the results.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is the latest version of Selenium
WebDriver?
Answer: version 4 (Find element(s) methods, Capabilities
and Actions class are different from version 3)
Question: What is Selenium Grid?
Answer: Tool to run Selenium tests on multiple machines
simultaneously, reducing the time to test the web
application on multiple browsers or operating systems
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What are the Selenium advantages?
Answer: free to use, supports multiple programming
languages e.g. Java, Python, C#, supports multiple
browsers e.g. Chrome, Firefox (each browser has it's
own driver)
Question: What are the Selenium limitations?
Answer: no support for testing desktop
applications, limited support for testing mobile
applications, no inbuilt reporting features
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How to get the correct browser driver for a
Selenium WebDriver session in Java?
Answer: download the correct browser driver or by using
WebDriverManager e.g.
import io.github.bonigarcia.wdm.WebDriverManager;
WebDriverManager.chromedriver().setup();
Question: How to create a Selenium WebDriver
session in Java?
Answer: by using WebDriver interface e.g.
WebDriver driver = new ChromeDriver();
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How to create a local Selenium WebDriver in Java?
Answer: by giving path to driver executable and using WebDriver
interface e.g.
System.setProperty("webdriver.chrome.driver", "/path/to/chromedri
ver");
WebDriver driver = new ChromeDriver();
Question: How to create a remote Selenium WebDriver in Java?
Answer: by using RemoteWebDriver class and the URL class e.g.
WebDriver driver = new RemoteWebDriver(new
URL("https://www.example.com"), DesiredCapabilities.chrome());
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: In Selenium Java, browser navigation can be done by which
command(s)?
Answer: driver.get(), driver.navigate().to(), driver.navigate().back(),
driver.navigate().forward() and driver.navigate().refresh();
Question: How to maximize the browser window?
Answer: driver.manage().window().maximize();
// You can follow me in LinkedIn at
https://www.linkedin.com/in/inderpsingh/
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How to get the web page title and the URL in the address
bar?
Answer: driver.getTitle(); driver.getCurrentUrl();
Question: How to verify the expected result?
Answer: By using JUnit e.g.
Assert.assertTrue(
driver.getTitle().indexOf("Software and Testing Training")>=0);
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What are the different locator strategies in Selenium
WebDriver with Java?
Answer: WebDriver can find element By id, By name, By class
name, By tag name, By link text, By partial link text, By CSS
selector or By XPath
Question: Why are relative XPaths preferred instead of absolute
XPaths as locators of elements?
Answer: Relative XPaths are more stable than absolute
(complete) XPaths, which fail if any part of the path changes even
slightly.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is InvalidSelectorException in Selenium WebDriver
with Java?
Answer: It is thrown when an invalid selector is used to locate an
element. To fix this issue, check the selector to see if it is correct and
that it is being used correctly.
Question: Relative locators in Selenium 4?
Answer: They identify the location,
above, below, toLeftOf, toRightOf or near (<50 px) another Web
Element with a simple(r) locator.
By submitLocator =
RelativeLocator.with(By.tagName("button")).below(By.id("simpleID"))
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
; Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you chain relative locators in Selenium 4?
Answer: Chaining relative locators means using multiple relative
locators e.g.
By login = RelativeLocator.with(By.tagName("button"))
.below(By.id("Password")).toRightOf(By.id("Cancel"));
Question: How do you interact with an input box in Selenium
WebDriver with Java?
Answer: WebElement i = driver.findElement(By.id("inputId"));
i.sendKeys("some value" + Keys.ENTER);
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you clear an input box in Selenium WebDriver with
Java?
Answer: By using the clear method but the input box must be editable e.g.
WebElement i = driver.findElement(By.id("inputId"));
i.clear();
Question: What is the difference between WebDriver close() and quit()
methods?
Answer: close() method closes the main browser window but the quit()
method (recommended) closes all the browser windows and deletes the
session.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How to write the if statement in Java?
Answer: 1) if (condition) { // code block to run if the condition is true
} else { // code block to run if the condition is false}
2) variable = (condition) ? expressionTrue : expressionFalse;
Question: How to execute some JavaScript in Selenium with Java?
Answer:
import org.openqa.selenium.JavascriptExecutor;
JavascriptExecutor js = (JavascriptExecutor) driver;
// open a blank tab in the browser
js.executeScript("window.open();");
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you interact with a link in Selenium WebDriver
with Java?
Answer: WebElement l = driver.findElement(By.linkText("Link Text"));
l.click();
Question: What if the link text is long or can change?
Answer: It is better to use partialLinkText with the stable part of the
link text e.g. WebDriverWait w = new WebDriverWait(driver, 30);
WebElement l =
w.until(ExpectedConditions.elementToBeClickable(By.partialLinkText(
"Partial Link Text"))); l.click();
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: Which element will WebDriver find if there are multiple
matching elements for the locator, as in WebElement a =
driver.findElement(By.className("answer"));
Answer: The first matching web element in the DOM
Question: How to find the 2nd or another element instead of the first
element?
Answer: By limiting the scope of finding it e.g.
WebElement question2 = driver.findElement(By.id("q2"));
WebElement a = question2.findElement(By.className("answer"));
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How to find the 2nd element using a single WebDriver
command?
Answer: By using CSS selector or XPath with # for ID and . for class
name e.g.
WebElement a = driver.findElement(By.cssSelector("#q2 .answer"));
Question: Which WebDriver command works on any web element?
Answer: click – it clicks the web element in the middle of the
element.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How to get the text shown in the browser by an
element?
Answer: By using the getText() method e.g.
String t = driver.findElement(By.cssSelector("#q1")).getText();
Question: How to get some attribute's value of a web element?
Answer: By using the getAttribute() method e.g.
String answer = driver.findElement(By.name("answer1")).
getAttribute("value");
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: When invoked on a web element, what does the submit()
method do?
Answer: It is used to submit a form. It works on any web element. But
in Selenium 4, it is recommended to click the specific form submission
button.
Question: How do you handle dropdowns?
Answer: by using Select class
WebElement dropdown = driver.findElement(By.id("dropdown"));
Select s = new Select(dropdown);
s.selectByVisibleText("Option 1");
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How to know if a dropdown is multi select
dropdown?
Answer: HTML: the select tag contains "multiple" attribute.
Selenium: d.isMultiple();
Question: Which method works for the multi select dropdown
but NOT for the single select dropdown?
getOptions(), getFirstSelectedOption(), deselectByVisibleText()
Answer: deselectByVisibleText()
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you verify the state e.g. visible or enabled of a
web element?
Answer: By using .isDisplayed() or .isEnabled() methods on the
element. .isSelected() method is to verify if a check box, radio
button and so on is selected.
Question: How do you handle alerts?
Answer: by using Alert class
Alert a = driver.switchTo().alert();
a.accept();
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is NoAlertPresentException?
Answer: It is thrown when there is no alert present on the page. To
fix this, verify that an alert is present before interacting with it. Also,
follow me in LinkedIn at https://www.linkedin.com/in/inderpsingh/
Question: How do you handle confirmations?
Answer: by using Alert class, a confirmation may be accepted (OK)
or dismissed (Cancel)
Alert c = driver.switchTo().alert();
c.dismiss();
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How can WebDriver handle the JavaScript popup with 2
buttons?
Answer: These are Confirmation (Confirm box) and Prompt
alert. Both have accept() (for OK) and dismiss() (for Cancel)
methods. Prompt has sendKeys() for text input.
Question: How do you handle frames in Selenium?
Answer: iframes (elements from any domain), switch to iframe e.g.
driver.switchTo().frame("frameName");
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is element not found exception in Selenium with
Java?
Answer: It can occur when the web element is not present on the
web page (e.g. DOM not loaded fully) or not interactable or is within
an iframe or shadow root or the element's locator has changed.
Question: How do you interact with an element in an iframe?
Answer: driver.switchTo().frame("iframeId");
WebElement element = driver.findElement(By.id("elementId"));
element.click();
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: In Selenium with Java, how can you switch to an iframe
with duplicate ID & name?
Answer: driver.switchTo().frame() switches to the first iframe with the
duplicate ID or name. driver.findElement() can find the iframe as a
WebElement to swtich to it. The frame index can also be used to
switch to it.
Question: In Selenium with Java, what is NoSuchFrameException?
Answer: It is thrown when the frame you are trying to switch to is not
present on the page. To fix this, verify that the frame is present on
the page before attempting to switch to it.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How to print the data of all the iframes on a web page?
Answer: for (WebElement f:
driver.findElements(By.tagName("iframe"))) {
frameData = "iframe id=" + f.getAttribute("id")
+ ", name=" + f.getAttribute("name")
+ ", source=" + f.getAttribute("src");
System.out.println(frameData);}
Question: What is a window handle?
Answer: It is a unique alphanumeric string of every window. The window
handle is generated and controlled by the browser for a single session.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you handle windows in Selenium Java?
Answer: String mWindow = driver.getWindowHandle();
for (String handle : driver.getWindowHandles())
{if(!mWindow.contentEquals(handle)) {
driver.switchTo().window(handle); break;}}
Question: How do you know how many windows or tabs are
open at a given time in Selenium testing?
Answer: driver.getWindowHandles().size()
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is implicit wait in Selenium WebDriver with Java?
Answer: WebDriver waits for a duration before it finds any element e.g.
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(15));
Question: How do you use explicit wait in Selenium WebDriver with Java?
Answer: with WebDriverWait and ExpectedConditions e.g.
WebDriverWait w = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement e =
w.until(ExpectedConditions.visibilityOfElementLocated(By.id("eId")));
Implict wait and explicit wait should not be used together.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What are the possible ExpectedConditions in Selenium
WebDriver with Java?
Answer: There are many e.g. alertIsPresent, elementToBeClickable ,
frameToBeAvailableAndSwitchToIt, textToBePresentInElement,
titleContains and visibilityOfElementLocated
Question: What is TimeoutException?
Answer: It is thrown when an operation takes longer than the
specified timeout period. To fix this issue, try increasing the timeout
period.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you use fluent wait in Selenium WebDriver?
Answer: FluentWait has timeout and polling frequency:
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(10))
.pollingEvery(Duration.ofSeconds(1))
.ignoring(NoSuchElementException.class);
WebElement e = wait.until(driver -> {return driver.findElement(By.id("eId"));});
Question: How do you perform a file upload in Selenium WebDriver with Java?
Answer: The type of input element has to be "file".
WebElement f = driver.findElement(By.id("fileInput"));
f.sendKeys("/path/to/file.txt");
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What are browser options in Selenium WebDriver with Java?
Answer: The capabilities shared by all browsers e.g. browserName,
browserVersion and pageLoadStrategy, which can be normal (default),
eager (faster) or none (fastest)
Question: How do you use Chrome-specific functionality in Selenium
WebDriver with Java?
Answer: by using the "ChromeOptions" class e.g.
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
WebDriver driver = new ChromeDriver(options);
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you use Edge-specific functionality in Selenium WebDriver
with Java?
Answer: by using the "EdgeOptions" class e.g.
EdgeOptions options = new EdgeOptions();
options.setPageLoadStrategy(PageLoadStrategy.EAGER);
WebDriver driver = new EdgeDriver(options);
Question: How do you use Firefox-specific functionality in Selenium
WebDriver with Java?
Answer: by using the latest version of geckodriver
FirefoxOptions options = new FirefoxOptions();
WebDriver driver = new FirefoxDriver(options);
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you use Internet Explorer-specific functionality?
Answer: Standalone Internet Explorer is not supported by Selenium
WebDriver, but it can run Microsoft Edge browser in Internet Explorer
Compatibility mode.
Question: Write code to print all links on a web page.
Answer: int i = 1; for (WebElement
link: driver.findElements(By.tagName("a")))
{System.out.println(i + ") LINK TEXT=" + link.getText() + " URL=" +
link.getAttribute("href")); i++;}
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What functionality does WebDriver support on browser
cookies?
Answer: add, get and delete an individual cookie, get all cookies,
delete all cookies
Question: How can you can see a Cookie's data in Selenium
WebDriver with Java?
Answer: driver.manage().getCookieNamed()
and driver.manage().getCookies()
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you add a cookie in Selenium WebDriver with Java?
Answer: driver.manage().addCookie(new Cookie("key1", "value1"));
Cookie c = driver.manage().getCookieNamed("key1");
System.out.println(c);
Question: How do you get the color of an element in Selenium WebDriver
with Java?
Answer: by the "getCssValue" method
Color B1Color =
Color.fromString(driver.findElement(By.id("button1")).getCssValue("colo
r"));
Color B1BGColor =
Color.fromString(driver.findElement(By.id("button1")).getCssValue("back
ground-color"));
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you handle an SVG web element in Selenium
WebDriver with Java?
Answer: SVG is scalable vector graphics format. It doesn't support
standard XPath locator.
WebElement s = driver.findElement(By.cssSelector("svg > circle"));
s.click();
Question: Which method in Actions API executes the keyboard
commands - keyDown(), keyUp(), sendKeys() or perform()?
Answer: perform() executes the one or more commands. Please
follow Inder P Singh (author of this document).
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is actions chaining in Actions API?
Answer: Putting multiple actions one after another e.g.
Actions a = new Actions(driver);
a.keyDown(sourceBox,
Keys.CONTROL).sendKeys("ac").keyUp(Keys.CONTROL).perform();
a.keyDown(targetBox,
Keys.CONTROL).sendKeys("v").keyUp(Keys.CONTROL).perform();
Question: How do you interact with a web element in the shadow DOM?
Answer: for open shadow DOM:
WebElement shadow = driver.findElement(By.cssSelector("#shadowHost"));
WebElement e = shadow.findElement(By.cssSelector("#shadowElement"));
e.click();
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you interact with a web element in the closed shadow DOM?
Answer: by executing JavaScript e.g.
WebElement shadow = (WebElement) driver.executeScript("return arguments[0].shadowRoot",
shadowHost);
WebElement e = shadow.findElement(By.cssSelector("#shadowElement"));
e.click();
Question: How do you interact with a web element in a nested shadow DOM?
Answer: by using findElement or executeScript multiple times e.g.
WebElement shadow1 = driver.findElement(By.cssSelector("#shadowHost1"));
WebElement shadow2 = (WebElement) driver.executeScript("return arguments[0].shadowRoot",
shadow1);
WebElement shadow3 = shadow2.findElement(By.cssSelector("#shadowHost2"));
WebElement e = (WebElement) driver.executeScript("return arguments[0].shadowRoot", shadow3);
e.click();
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you use the Actions API in Selenium WebDriver with
Java?
Answer: by using the Actions class e.g. Actions a = new Actions(driver);
WebElement e = driver.findElement(By.id("elementId"));
a.moveToElement(e).click().perform();
Question: What is StaleElementReferenceException?
Answer: a) It is thrown when the element has been modified or removed
from the page after it was previously located. The element needs to be re-
located. b) If the element is no longer attached to the DOM, the refresh()
method needs to be called to refresh the web page and the element needs
to be located again.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How to perform mouse hover in Selenium WebDriver?
Answer: By using Actions API e.g.
Actions a = new Actions(driver);
WebElement menu1 = driver.findElement(By.id("menu3"));
a.moveToElement(menu1).perform();
Question: Does WebDriver support mouse wheel operation by the
user?
Answer: Yes, Actions API has scrollToElement(), scrollByAmount() etc.
methods. But, they are supported in Chromium browsers only in 4.2+
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is TakesScreenshot in Selenium Java?
Answer: It is an interface that provides WebDriver getScreenshotAs()
method to take screenshot in OutputType like FILE or BYTES.
Question: What is WebDriverException?
Answer: It is thrown when there is an issue with the WebDriver itself,
such as a connection issue or an issue with the browser. To fix this
issue, you can try restart the WebDriver or check for updates.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How can you print the stack trace of the exception?
Answer: By printing the exception object using
System.out.println(exception);
Question: How can you prevent threading defects in your Selenium
Java code?
Answer: By using ThreadGuard, which ensures that the same thread
that created the driver can call it, else it throws a thread safety
exception
e.g. private WebDriver driver = ThreadGuard.protect(new
ChromeDriver());
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is the architecture of Selenium grid?
Answer: one hub (central) and one or more nodes (to run the tests),
the hub commands nodes based on test capabilities needed and the
nodes availability
Question: What are the Selenium grid features?
Answer: Support for running tests on remote machines (on-premises
or cloud), running tests on different browser and operating system
combinations, scale the number of nodes up or down depending on
the load, a proxy server to route traffic to the nodes
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you scale the number of nodes in Selenium grid?
Answer: To add a node, start a new node with the desired capabilities
and specify the URL of the hub. To remove a node, stop the node
process. You may also use virtualization tools like Docker.
Question: How do you use Selenium grid in Selenium WebDriver with
Java?
Answer: use the "RemoteWebDriver" class and specify the URL of the
Selenium grid hub.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you configure the Selenium grid hub?
Answer: Specify the following options in the "configuration" file:
"port" - the port number to listen on
"host" - the hostname or IP address to bind to
"newSessionWaitTimeout" - the maximum time to wait for a new session to be
created before timing out
Question: How do you configure the Selenium grid node?
Answer: Specify the following options in the "configuration" file:
"port" - the port number to listen on
"host" - the hostname or IP address to bind to
"maxSession" - the maximum number of sessions that can be created on the node
"capabilities" - a list of the capabilities that the node supports
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you use Selenium grid to run tests on different browser and
operating system combinations?
Answer: use the desired capabilities before creating a new session:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setPlatform(Platform.WINDOWS);
WebDriver driver = new RemoteWebDriver(new URL("https://www.example.com"),
capabilities);
Question: What are the advantages of using Page Object Model (POM)?
Answer: Reduce code duplicity (to find the web elements and interact with them)
Maintainability: If the UI changes, the update needs to be done in a single place (in the
specific page object).
Readability: The web page specific code and test code are separate.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is a Page Object in Page Object Model (POM)?
Answer: It is a class that represents a single web page. It should have
the locators of the web page but no assertions, which should be in the
test code. Page Factory pattern makes it simpler to create page
objects.
Question: In Page Object Model, how can you verify that the correct
web page has loaded?
Answer: The correct web page and any critical web elements can be
verified in the Page Object constructor method(s).
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is data parameterization?
Answer: Using variable test data (e.g. in CSV file, Excel file or
database) instead of static test data (e.g. hard-coded data in scripts)
Question: Name a few frameworks used in Selenium with Java.
Answer: Test frameworks e.g. JUnit and TestNG, natural language
frameworks e.g. Cucumber and test automation frameworks e.g.
MaxTAF Cloud (logging, read Excel etc.)
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What are the annotations in JUnit?
Answer: Annotations are put before the Java method definitions e.g.
@BeforeClass annotation - runs the method before all tests
@AfterClass annotation - runs the method after all tests
@Before annotation - runs the method before each test
@After annotation - runs the method after each test
@Test(timeout=5000)
@RepeatedTest(6)
Question: In JUnit, what is the difference between Before and BeforeClass?
Answer: @Before runs the method before each test method. @BeforeClass
runs the method once before all test methods.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What are the main tasks in a Selenium Java project?
Answer: - Test Case and Test Data Analysis & Planning
- Selenium Framework Identification and Configuration
- Design Pattern Implementation (POM, Data Driven Testing etc.)
- Write Test Automation (Operations and Validation)
- Logging and Screenshots Implementation
- Test Results Analysis
Question: In Selenium IDE, what is base URL?
Answer: URL (link) of the application under test. It is shared in all the
tests of the project. Follow me in LinkedIn at
https://www.linkedin.com/in/inderpsingh/
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How can you run the Selenium IDE test in a different
browser?
Answer: by using Selenium IDE command line runner
Question: How can you run the Selenium IDE test in a different
browser?
Answer: by using Selenium IDE command line runner
Question: How does the if command work in Selenium IDE?
Answer: if, else if, else, end command has a JavaScript expression
after if. When the expression is true, it runs the commands until else
if, else or end.
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: How do you implement loops in Selenium IDE?
Answer: By using the commands: times, do...repeat if, while, for each
Question: How do you convert Selenium IDE tests to Selenium
WebDriver code?
Answer: By Export to Java/ JUnit, JavaScript/Mocha, Python/Pytest or
C#/NUnit
Question: What is Selenium RC?
Answer: Selenium RC is the original Selenium 1. It has the Selenium
server and client libraries. It is still available but not supported
anymore. Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.
Question: What is Selenium 2?
Answer: Selenium 1 was re-written with the code of WebDriver
(easier and more object-oriented). With Selenium 2, you can use
WebDriver API calls and also use Selenium RC.
Question: What is Selenium 3?
Answer: Selenium 3 has only WebDriver but not Selenium RC. Now,
Selenium 4 is available, which follows the W3C WebDriver
specifications. Follow me in LinkedIn at
https://www.linkedin.com/in/inderpsingh/
Download for reference Like Share View video https://youtu.be/e5BLn9IGrF0
Software and Testing Training YouTube Channel https://youtube.com/@QA1
Software Testing Space Blog https://inderpsingh.blogspot.com/
Copyright © 2025 All Rights Reserved.