




















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















































































Question 1. Which of the following statements about the Java Virtual Machine (JVM) is true? A) It compiles source code directly to machine code B) It executes bytecode generated by the Java compiler C) It is optional for running Java programs D) It only runs on Windows OS Answer: B Explanation: The JVM loads and executes the bytecode produced by the Java compiler, providing platform‑independent execution. Question 2. In Java, which access modifier allows a member to be visible only within its own package and to subclasses in other packages? A) private B) protected C) default (package‑private) D) public Answer: B Explanation: protected members are accessible within the same package and also in subclasses even if they are in different packages. Question 3. Which Java collection guarantees insertion order and allows duplicate elements? A) HashSet B) TreeSet C) ArrayList D) LinkedHashMap Answer: C
Explanation: ArrayList maintains the order in which elements are added and permits duplicates. Question 4. What is the purpose of the throws keyword in a method declaration? A) To catch an exception inside the method B) To re‑throw a caught exception C) To declare that the method may propagate specific checked exceptions D) To convert a checked exception into an unchecked one Answer: C Explanation: throws indicates that the method does not handle certain checked exceptions and they must be dealt with by the caller. Question 5. Which of the following HTML tags defines a container for table header cells? A) <thead> B) <th> C) <tr> D) <tbody> Answer: B Explanation: <th> is used inside a table row to denote header cells. Question 6. In CSS, which selector will match any element whose id attribute starts with “login”? A) #login* B) *[id^='login'] C) .login* D) id^=login
B) driver.getPageTitle(); C) driver.title(); D) driver.fetchTitle(); Answer: A Explanation: getTitle() returns the title string of the active page. Question 10. What is the default timeout for an implicit wait if it is not set explicitly? A) 0 seconds B) 5 seconds C) 10 seconds D) 30 seconds Answer: A Explanation: By default, Selenium does not wait implicitly; the timeout is 0 seconds unless configured. Question 11. Which of the following statements about WebDriverWait is correct? A) It polls the DOM continuously without any interval. B) It only works with ExpectedConditions from the org.openqa.selenium.support.ui package. C) It throws NoSuchElementException immediately if the condition is not met. D) It can be configured with a custom polling interval and ignored exceptions. Answer: D Explanation: WebDriverWait allows setting a polling frequency and specifying exceptions to ignore during the wait.
Question 12. In Selenium Grid, what is the role of the Hub? A) Executes tests on multiple browsers simultaneously. B) Stores test data and reports. C) Receives test requests and distributes them to registered Nodes. D) Provides a graphical interface for test creation. Answer: C Explanation: The Hub acts as a central point that receives test execution requests and forwards them to appropriate Nodes. Question 13. Which of the following is the correct way to switch to an iframe using its name attribute? A) driver.switchTo().frame("iframeName"); B) driver.switchTo().iframe("iframeName"); C) driver.switchTo().frameByName("iframeName"); D) driver.switchTo().frameById("iframeName"); Answer: A Explanation: switchTo().frame(String nameOrId) accepts either the name or the id of the iframe. Question 14. How can you retrieve the value of a CSS property (e.g., background-color) of a WebElement? A) element.getCssValue("background-color"); B) element.getAttribute("background-color"); C) element.getStyle("background-color"); D) element.getProperty("background-color"); Answer: A
Answer: B Explanation: Apache POI provides APIs for reading and writing Microsoft Office formats, including .xlsx and .xls. Question 18. What does the @DataProvider annotation in TestNG do? A) Supplies a set of parameters to a test method for multiple iterations. B) Marks a method as a test case. C) Configures the test suite execution order. D) Generates HTML reports automatically. Answer: A Explanation: @DataProvider methods return Object[][] arrays that feed test methods with different data sets. Question 19. Which Selenium command allows you to execute arbitrary JavaScript in the context of the currently loaded page? A) driver.executeScript(); B) driver.runJavaScript(); C) driver.evaluate(); D) driver.jsExecutor(); Answer: A Explanation: JavascriptExecutor interface provides executeScript(String script, Object... args) to run JavaScript. Question 20. In a test, you need to capture a screenshot only when a failure occurs. Which TestNG listener is most appropriate?
A) IInvokedMethodListener B) ITestListener C) ISuiteListener D) IExecutionListener Answer: B Explanation: ITestListener.onTestFailure() can be overridden to take a screenshot when a test fails. Question 21. Which of the following statements about the Select class in Selenium is FALSE? A) It can be used only with <select> HTML elements. B) selectByVisibleText() selects an option based on the text shown to the user. C) deselectAll() works for single‑select dropdowns as well. D) getOptions() returns a list of all <option> elements. Answer: C Explanation: deselectAll() is applicable only to multi‑select dropdowns; calling it on a single‑select throws an exception. Question 22. When using Actions class, which method chain performs a mouse hover over an element? A) moveToElement(element).click().build().perform(); B) clickAndHold(element).release().build().perform(); C) moveToElement(element).build().perform(); D) doubleClick(element).build().perform(); Answer: C
B) <dependency><groupId>com.seleniumhq</groupId><artifactId>selenium- core</artifactId><version>4.10.0</version></dependency> C) <dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium- api</artifactId><version>4.10.0</version></dependency> D) <dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium- driver</artifactId><version>4.10.0</version></dependency> Answer: A Explanation: The official Maven artifact for Selenium Java is selenium-java under the org.seleniumhq.selenium group. Question 26. Which Java keyword is used to inherit from a superclass? A) implements B) extends C) inherits D) super Answer: B Explanation: extends establishes an inheritance relationship between a subclass and its superclass. Question 27. What is the output of the following Java code? System.out.println(5 + "5"); A) 10 B) 55 C) Compilation error D) 5 5 Answer: B Explanation: The integer 5 is concatenated with the string "5", resulting in the string "55".
Question 28. Which of the following statements about final variables in Java is TRUE? A) They can be reassigned once after initialization. B) They must be initialized at the time of declaration. C) They cannot be declared as static. D) They can be changed using reflection. Answer: B Explanation: A final variable must be assigned exactly once, either at declaration or in a constructor; after that it cannot be changed. Question 29. In HTML, which attribute uniquely identifies an element within a document? A) class B) id C) name D) type Answer: B Explanation: The id attribute must be unique across the entire HTML document. Question 30. Which CSS property controls the space between lines of text? A) margin B) padding C) line-height D) letter-spacing Answer: C
D) Map<String, Integer> map = new LinkedHashMap<>(); Answer: C Explanation: While syntactically correct, TreeMap is not a HashMap; the question asks for a way to instantiate a HashMap. Question 34. In Selenium, which method would you use to simulate pressing the ENTER key on a text field? A) element.sendKeys(Keys.ENTER); B) element.pressEnter(); C) element.keyPress(Keys.ENTER); D) element.type(Keys.ENTER); Answer: A Explanation: sendKeys(Keys.ENTER) sends the ENTER keystroke to the element. Question 35. Which of the following statements about the @FindBy annotation is FALSE? A) It can locate elements by id, name, css, or xpath. B) It must be used together with PageFactory.initElements(). C) It can be applied to methods that return WebElement. D) It supports locating multiple elements using @FindBys. Answer: C Explanation: @FindBy is applied to fields (or List<WebElement>), not to methods. Question 36. What does the @BeforeSuite annotation in TestNG signify? A) Method runs before each test class.
B) Method runs before any test in the entire suite. C) Method runs after all tests have completed. D) Method runs before each test method. Answer: B Explanation: @BeforeSuite executes once before any tests in the suite start. Question 37. Which of the following Java keywords is used to handle a situation where a method may throw a checked exception without catching it? A) catch B) finally C) throw D) throws Answer: D Explanation: throws propagates the exception to the caller. Question 38. In Selenium, which command is used to clear the text of an input field? A) element.empty(); B) element.clear(); C) element.reset(); D) element.delete(); Answer: B Explanation: clear() removes any existing text from an input or textarea element.
Explanation: pageLoadTimeout defines how long WebDriver will wait for the page load event. Question 42. Which of the following is the correct way to declare a TestNG test method that belongs to the “smoke” group? A) @Test(groups = {"smoke"}) B) @Test(group = "smoke") C) @Test(category = "smoke") D) @Test(tag = "smoke") Answer: A Explanation: The groups attribute accepts an array of group names. Question 43. In Java, which interface must a class implement to be used as a lambda expression target? A) Serializable B) Cloneable C) FunctionalInterface (or any interface with a single abstract method) D) Runnable only Answer: C Explanation: Any interface with exactly one abstract method is a functional interface; it can be implemented via a lambda. Question 44. Which Selenium command can be used to retrieve the current URL of the page? A) driver.getCurrentUrl(); B) driver.getUrl(); C) driver.currentUrl();
D) driver.fetchUrl(); Answer: A Explanation: getCurrentUrl() returns the URL of the page currently loaded in the browser. Question 45. When using the Select class, which method returns the first selected option? A) getFirstSelectedOption() B) getSelectedOption() C) getSelected() D) getFirstOption() Answer: A Explanation: getFirstSelectedOption() returns the first selected <option> element. Question 46. Which of the following statements about Thread.sleep() in Selenium tests is TRUE? A) It is the recommended way to handle dynamic waits. B) It pauses the execution of the current thread for a specified time. C) It automatically detects when an element becomes visible. D) It replaces the need for explicit waits. Answer: B Explanation: Thread.sleep() simply halts execution; it does not wait for any condition. Question 47. In a Maven pom.xml, which tag defines the version of the project itself? A) <artifactId> B) <groupId> C) <version>
B) public class Browser { enum { CHROME, FIREFOX, EDGE } } C) enum Browser = { CHROME; FIREFOX; EDGE; } D) class Browser { public static final String CHROME, FIREFOX, EDGE; } Answer: A Explanation: The standard enum declaration uses enum Browser { ... }. Question 51. Which Selenium method would you use to retrieve the attribute “value” of an input element? A) element.getAttribute("value"); B) element.getProperty("value"); C) element.getCssValue("value"); D) element.getText("value"); Answer: A Explanation: getAttribute() returns the value of the specified attribute. Question 52. In TestNG, which XML element defines the order in which test classes are executed? A) <suite> B) <test> C) <classes> D) <methods> Answer: C Explanation: Within a <test> tag, the <classes> element lists test classes in the order they should run.
Question 53. Which of the following is the correct way to declare a constant integer named MAX_RETRY with value 5 in Java? A) final int MAX_RETRY = 5; B) static int MAX_RETRY = 5; C) const int MAX_RETRY = 5; D) int MAX_RETRY = final 5; Answer: A Explanation: final makes the variable constant; it can also be static final if shared. Question 54. Which Selenium WebDriver method is used to switch the context to a newly opened browser window? A) driver.switchTo().newWindow(WindowType.WINDOW); B) driver.switchTo().window(handle); where handle is obtained from getWindowHandles() C) driver.openNewWindow(); D) driver.changeWindow(); Answer: B Explanation: After obtaining the new window’s handle, switchTo().window(handle) changes focus. Question 55. In Java, which keyword is used to prevent a class from being subclassed? A) static B) final C) abstract D) sealed Answer: B