Q: If you are using multiple @test annotations in a single JUnit file and the methods c_test, a_test, and b_test are not arranged alphabetically in the code, then in which sequence will they be executed?
✅ Answer: The test runner runs the methods in alphabetical order.
Explanation: In JUnit, by default, test methods execute in lexicographical (alphabetical) order unless a specific order is defined using @FixMethodOrder.
⸻
Question 2
Q: Which command helps to work with a specific window of your choice in Selenium WebDriver before locating elements within it?
✅ Answer: driver.switchTo().window(windowName)
Explanation: This command switches the driver’s focus to the specified browser window so that Selenium can interact with elements inside it.
⸻
Question 3
Q: Differences between Arrays & ArrayList — Pick the odd one out.
✅ Answer: Arrays and ArrayList can hold both primitive and object datatypes.
Explanation: This is incorrect — arrays can hold both primitives and objects, but ArrayList can hold only objects (not primitives).
⸻
Question 4
Q: Which of the below annotations runs once after all methods in the class?
✅ Answer: @AfterClass
Explanation: The @AfterClass annotation is used to execute code only once after all test methods in a class have run.
⸻
Question 5
Q: If there are two identical link objects on a webpage, which link is selected when using linkText or partialLinkText?
✅ Answer: Clicks on first match.
Explanation: Selenium’s findElement() returns and interacts with the first matching element it encounters.
⸻
Question 6
Q: To get all links on a webpage, which is the correct code?
✅ Answer:
List allLinks = driver.findElements(By.tagName("a"));
Top comments (1)
MCQ
Set 1:
Question 1
Q: If you are using multiple @test annotations in a single JUnit file and the methods c_test, a_test, and b_test are not arranged alphabetically in the code, then in which sequence will they be executed?
✅ Answer: The test runner runs the methods in alphabetical order.
Explanation: In JUnit, by default, test methods execute in lexicographical (alphabetical) order unless a specific order is defined using @FixMethodOrder.
⸻
Question 2
Q: Which command helps to work with a specific window of your choice in Selenium WebDriver before locating elements within it?
✅ Answer: driver.switchTo().window(windowName)
Explanation: This command switches the driver’s focus to the specified browser window so that Selenium can interact with elements inside it.
⸻
Question 3
Q: Differences between Arrays & ArrayList — Pick the odd one out.
✅ Answer: Arrays and ArrayList can hold both primitive and object datatypes.
Explanation: This is incorrect — arrays can hold both primitives and objects, but ArrayList can hold only objects (not primitives).
⸻
Question 4
Q: Which of the below annotations runs once after all methods in the class?
✅ Answer: @AfterClass
Explanation: The @AfterClass annotation is used to execute code only once after all test methods in a class have run.
⸻
Question 5
Q: If there are two identical link objects on a webpage, which link is selected when using linkText or partialLinkText?
✅ Answer: Clicks on first match.
Explanation: Selenium’s findElement() returns and interacts with the first matching element it encounters.
⸻
Question 6
Q: To get all links on a webpage, which is the correct code?
✅ Answer:
List allLinks = driver.findElements(By.tagName("a"));
Explanation: All hyperlinks use the HTML tag, so finding by tagName("a") returns all link elements.
⸻
Question 7
Q: What is the output of the given code?
✅ Answer: The code will execute successfully and it enters the value into the textbox.
Explanation: The element is found using By.name("txt1"), and if enabled, it will successfully perform sendKeys("Welcome").
⸻
Question 8
Q: Choose the correct option to explicitly wait for a pop-up to be visible.
✅ Answer:
WebDriverWait wait = new WebDriverWait(driver, 20);
Element element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("...")));
Explanation: WebDriverWait with ExpectedConditions.visibilityOfElementLocated explicitly waits for the element to be visible.
⸻
Question 9
Q: When you add an explicit wait and the element is not visible within the specified time, what error do you get?
✅ Answer: TimeoutException
Explanation: When the wait time expires without finding the element, Selenium throws a TimeoutException.
⸻
Question 10
Q: Difference between static and dynamic binding — choose the incorrect option.
✅ Answer: Both are same.
Explanation: Static binding happens at compile time (method overloading), and dynamic binding happens at runtime (method overriding). They are not the same.
Question 11
Q: Assume that you created an HTML page with hyperlinks and later noticed that there are multiple matches. What will be the result if you have used either linkText or partialLinkText?
Options:
O It selects all the matches
O It selects only the last match
✅ It selects the first match
O It will generate an error
✅ Correct Answer: It selects the first match
Question 12:
“Image links are images that act as references to other sites or sections within the same page. But image links basically have no link texts at all.”
Options:
False
True
Partially correct
None
✅ Correct Answer: True
Question 14
Q: What functionality does WebDriver support on browser cookies?
Options:
A. add and delete an individual cookie
B. delete all cookies
✅ Both A & B
none of the above
✅ Correct Answer: Both A & B
Question 15
Q: A web designer is frequently changing the web page. UI element functionality must be regression tested. Which locators from the below are best in order to automate elements? (Choose more than one option)
Options:
Xpath
DOM
✅ ID
✅ Name
✅ Correct Answers: ID and Name
Set 2:
Question 1
Q: Choose the incorrect option on the difference between final and finally keywords in Java.
✅ Answer: You can use finally without a try block but catch block is a must.
Explanation:
This is incorrect because the finally block must always follow a try block, though a catch block is optional.
⸻
Question 2
Q: Pick the odd one out for getWindowHandles() or getWindowHandle() methods of WebDriver.
✅ Answer: The return type for both the methods is a list object.
Explanation:
This is incorrect.
• getWindowHandle() returns a String (the current window ID).
• getWindowHandles() returns a Set of all open window handles — not a List.
⸻
Question 3
Q: What is the output of the below code (textbox with name txt1)?
✅ Answer: The code will execute successfully and it enters the value into the textbox.
Explanation:
If the element with name txt1 exists and is enabled, the statement sendKeys("Welcome") will run successfully without errors.
⸻
Question 4
Q: If there are 2 identical link objects on a web page, which link is selected when linkText or partialLinkText is used?
✅ Answer: Clicks on first match.
Explanation:
Selenium’s findElement() always finds the first matching element in the DOM.
⸻
Question 5
Q: Identify the correct XPath to locate the Radio button named “Business”. (Choose two)
✅ Answer:
• //[@value='Business']
• //[@id='fromRegisterPopUP']//input[@value='Business']
Explanation:
Both accurately identify the radio button input element having value="Business".
⸻
Question 6
Q: If you are using multiple @Test annotations in a single JUnit file, and methods c_test, a_test, b_test are not alphabetically arranged, in which sequence will they be executed?
✅ Answer: The test runner runs the methods in alphabetical order.
Explanation:
JUnit executes tests alphabetically (lexicographically) by default unless customized using @FixMethodOrder.
⸻
Question 7
Q: What is the difference between WebDriver close() and quit() methods?
✅ Answer: close() method closes the main browser window but the quit() method closes all the browser windows including popups.
Explanation:
close() affects only the active window, while quit() shuts down the WebDriver instance completely.
⸻
Question 8
Q: How to maximize the browser in WebDriver?
✅ Answer: driver.manage().window().maximize();
Explanation:
This is the correct WebDriver command to maximize the browser window.
⸻
Question 9
Q: Select the correct Selenium WebDriver statement to work with iframes.
✅ Answer: All of the above.
Explanation:
You can switch to an iframe using any of these methods:
• driver.switchTo().frame(ID)
• driver.switchTo().frame(name)
• driver.switchTo().frame(index)
⸻
Question 10
Q: The ___ collection object is used to store unique values of strings in a variable.
✅ Answer: Set
Explanation:
A Set in Java does not allow duplicate elements and is ideal for storing unique values.
Question 11
Q: Sam is testing a web application and wants to verify if all the links on a web page are working correctly. As a first step, he wants to get the number of links that are there on the webpage. Choose the correct option to achieve this.
✅ Answer:
List allLinks = driver.findElements(By.tagName("a"));
Explanation:
All hyperlinks on a webpage are represented using the tag in HTML.
Using driver.findElements(By.tagName("a")) returns a list of all such elements, allowing you to count or validate them.
⸻
Question 12
Q: Which method is used to open a URL in the browser when working with the WebDriver?
✅ Answer: Both A & B
(i.e., driver.get(url) and driver.navigate().to(url))
Explanation:
Both methods are valid in Selenium for launching a webpage:
• driver.get(url) directly opens the URL.
• driver.navigate().to(url) is an alternative that allows additional navigation features like back/forward.
⸻
Question 13
Q: Choose the correct option for the main disadvantage of arrays in Java.
✅ Answer: It holds elements that belong to one datatype only.
Explanation:
Arrays in Java are homogeneous, meaning they can store only one data type at a time.
For example, you cannot store both int and String in the same array.
⸻
Question 14
Q: Which of the below annotations runs once after all methods in the class?
✅ Answer: @AfterClass
Explanation:
In JUnit/TestNG, the @AfterClass annotation is used to execute code only once after all the test methods in a class have run.
⸻
Question 15
Q: Does Selenium have Excel reading methods? (Choose more than one option.)
✅ Answer:
• Use POI jars from Apache to work with .xls and .xlsx files
• jxl jar to work with .xls file
Explanation:
Selenium itself cannot read Excel files directly.
You need external libraries such as:
• Apache POI → Supports both .xls and .xlsx
• JXL (Java Excel API) → Works with .xls files only
Set 3 :
Question 1
Q: What functionality does WebDriver support on browser cookies?
✅ Answer: Both A & B
Explanation:
WebDriver provides methods to:
• Add and delete individual cookies
• Delete all cookies
via driver.manage().addCookie(), driver.manage().deleteCookie(), and driver.manage().deleteAllCookies().
⸻
Question 2
Q: Which of the following is not a type of locator?
✅ Answer: tag
Explanation:
Valid locators in Selenium include id, name, className, xpath, cssSelector, linkText, partialLinkText, and tagName.
Hence, tag is not valid — it should be tagName.
⸻
Question 3
Q: Choose the CSS selector to identify the below textbox uniquely.
✅ Answer: input.q[value="Search"]
Explanation:
In CSS, the # is for id, . for class, and attributes are enclosed in brackets.
Here q is the id, so correct syntax is input#q[value="Search"].
⸻
Question 4
Q: How do we run setup() and teardown() methods once for all tests in the class for JUnit framework?
✅ Answer: Use @BeforeClass annotation before all tests and @AfterClass after all tests.
Explanation:
In JUnit, @BeforeClass and @AfterClass run once per class — ideal for setup/cleanup across all tests.
⸻
Question 5
Q: Sam wants to get the total number of links on a webpage. Which is the correct code?
✅ Answer:
List allLinks = driver.findElements(By.tagName("a"));
Explanation:
All links are represented by tags in HTML, so locating by tagName("a") captures all hyperlinks.
⸻
Question 6
Q: Pick the odd one out for getWindowHandles() or getWindowHandle() methods.
✅ Answer: The return type for both the methods is a list object.
Explanation:
getWindowHandle() → returns a String (current window ID).
getWindowHandles() → returns a Set (all open windows).
Hence, they do not return a List.
⸻
Question 7
Q: Which method is used to open a URL in the browser when working with WebDriver?
✅ Answer: Both A & B (driver.get(url) and driver.navigate().to(url))
Explanation:
Both methods open a webpage. get() is straightforward; navigate().to() provides extra navigation features.
⸻
Question 8
Q: Choose the correct option to explicitly wait for a particular pop-up to be visible on the webpage.
✅ Answer:
WebDriverWait wait = new WebDriverWait(driver, 20); Element element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("...")));
Explanation:
Explicit waits use WebDriverWait with ExpectedConditions to wait for specific events like visibility or alerts.
⸻
Question 9
Q: Differences between Arrays & ArrayList — Pick the odd one out.
✅ Answer: Arrays and ArrayList can hold both primitive and object datatypes.
Explanation:
This is incorrect — Arrays can hold both primitive and objects, but ArrayList can hold only objects.
⸻
Question 10
Q: If there are multiple identical hyperlinks and you use linkText or partialLinkText, which one is selected?
✅ Answer: It selects the first match.
Explanation:
findElement() always interacts with the first matching element in the DOM.
Question 11
Q: Choose the incorrect option on difference between final and finally keyword in Java.
✅ Answer: You can use finally without a try block but catch block is a must.
Explanation:
This is incorrect because the finally block must always be associated with a try block (though catch is optional).
Question 12
Q: Which of the below annotation runs once after all methods in the class?
✅ Answer: @AfterClass
Explanation:
In JUnit/TestNG, the @AfterClass annotation runs once after all the test methods in a class have finished execution.
⸻
Question 13
Q: What is overloading and overriding? Choose the incorrect option.
✅ Answer: In method overloading and method overriding the parameters will be the same.
Explanation:
This statement is wrong because:
• Overloading → same method name, different parameters.
• Overriding → same method name and same parameters (in subclass).
⸻
Question 14
Q: If you click a link that launches a separate window in WebDriver, which command helps you switch to that window?
✅ Answer: driver.switchTo().window(windowName);
Explanation:
The switchTo().window() method is used to shift focus to a different browser window or tab.
⸻
Question 15
Q: Assume there are two links on a webpage — “REGISTER” and “Register here”. Both contain “egis”. The By.partialLinkText("egis") method will access these two links depending on:
✅ Answer: Position of the links (left to right).
Explanation:
When multiple elements match, Selenium interacts with the first matching element found in the DOM (i.e., from left to right).