







































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 Selenium component allows recording of user actions without writing code? A) WebDriver B) Selenium Grid C) Selenium IDE D) TestNG Answer: C Explanation: Selenium IDE is a browser extension that records user interactions and generates test scripts automatically, requiring no programming. Question 2. In Selenium Grid, what is the role of the Hub? A) Executes tests on remote browsers B) Stores test data C) Manages and distributes test requests to Nodes D) Provides a GUI for test creation Answer: C Explanation: The Hub receives test requests and routes them to registered Nodes that have the required browser/OS combinations. Question 3. Which protocol did Selenium WebDriver replace to become W3C standard compliant? A) HTTP Wire Protocol B) JSON Wire Protocol C) SOAP Protocol D) RESTful API Answer: B Explanation: The JSON Wire Protocol was the original communication protocol; it has been superseded by the W3C WebDriver standard. Question 4. What is the primary advantage of using CSS selectors over XPath in Selenium? A) Ability to navigate backwards in the DOM
B) Faster execution in most browsers C) Supports text node selection D) Works with all browsers equally Answer: B Explanation: CSS selectors are generally faster because browsers natively support them; XPath can be slower, especially in Internet Explorer. Question 5. Which of the following statements about the @FindBy annotation in Page Factory is true? A) It can locate elements only by ID B) It must be used with PageFactory.initElements() C) It replaces the need for WebDriver instances D) It automatically waits for elements to be visible Answer: B Explanation: @FindBy works with PageFactory.initElements() to initialize WebElement fields defined in a Page Object. Question 6. In Java, which collection is most appropriate for storing a list of WebElements while preserving insertion order? A) HashSet B) TreeMap C) ArrayList D) LinkedHashMap Answer: C Explanation: ArrayList maintains insertion order and allows duplicate elements, making it suitable for ordered WebElement collections. Question 7. Which JUnit annotation is executed once before any test methods in the class are run? A) @Before B) @BeforeClass C) @BeforeAll
Explanation: driver.switchTo().alert() returns the Alert object, enabling acceptance, dismissal, or text retrieval. Question 11. Which of the following is NOT a valid way to locate an element by link text? A) By.linkText("Home") B) By.partialLinkText("Hom") C) By.linkText("home") – case-sensitive D) By.linkText("Home ") – trailing space Answer: D Explanation: By.linkText matches the exact visible text; trailing spaces cause a mismatch, making D invalid. Question 12. In Selenium, what is the purpose of driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));? A) Waits exactly 10 seconds before each command B) Sets a maximum wait time for element location attempts C) Pauses the test for 10 seconds after each step D) Configures the page load timeout Answer: B Explanation: Implicit wait tells WebDriver to poll the DOM for up to the specified time when trying to locate elements. Question 13. Which Java keyword is used to create a subclass that inherits methods from a parent class? A) implements B) extends C) super D) this Answer: B Explanation: extends establishes an inheritance relationship between a subclass and its superclass.
Question 14. Which method of the Select class selects an option based on its visible text? A) selectByValue() B) selectByIndex() C) selectByVisibleText() D) selectByAttribute() Answer: C Explanation: selectByVisibleText(String text) selects the `
Explanation: NoSuchElementException indicates that the element could not be found in the DOM. Question 21. Which Java construct is best suited for representing a constant set of browser types (e.g., CHROME, FIREFOX, EDGE)? A) Interface B) Abstract class C) Enum D) Static final variables Answer: C Explanation: Enums provide a type-safe way to define a fixed set of constants. Question 22. What is the effect of calling driver.manage().deleteAllCookies();? A) Clears the browser cache B) Removes all session and persistent cookies for the current domain C) Clears local storage data only D) Logs the user out of the application automatically Answer: B Explanation: deleteAllCookies() removes all cookies associated with the current domain, affecting session data. Question 23. In Selenium, which method returns the current page’s source HTML as a string? A) driver.getPageSource(); B) driver.getSource(); C) driver.getHTML(); D) driver.retrieveSource(); Answer: A Explanation: getPageSource() fetches the complete HTML markup of the current page.
Question 24. Which of the following is a valid way to perform a double-click action using the Actions class? A) new Actions(driver).doubleClick(element).perform(); B) driver.doubleClick(element); C) Actions.doubleClick(driver, element); D) driver.actions().doubleClick(element); Answer: A Explanation: The Actions API provides doubleClick(WebElement) which must be followed by perform(). Question 25. Which Java keyword is used to ensure that a variable cannot be reassigned after its initial value is set? A) static B) final C) const D) immutable Answer: B Explanation: final makes a variable a constant after its first assignment. Question 26. When using WebDriverWait, which class represents the condition to wait for? A) ExpectedCondition B) WaitCondition C) Condition D) Predicate Answer: A Explanation: ExpectedCondition is an interface that defines the condition evaluated by WebDriverWait. Question 27. Which of the following locators is generally the fastest according to Selenium’s best practices? A) By.id()
Question 30. In a test suite, what is the purpose of a “BaseTest” class? A) To contain all test data B) To centralize driver setup/teardown and common utilities C) To hold only Page Object definitions D) To generate HTML reports Answer: B Explanation: A BaseTest provides shared setup and cleanup logic (e.g., initializing WebDriver) that other test classes inherit. Question 31. Which method of the WebElement interface checks whether an element is currently visible to the user? A) isEnabled() B) isDisplayed() C) isSelected() D) isVisible() Answer: B Explanation: isDisplayed() returns true if the element’s height and width are greater than zero and it is not hidden by CSS. Question 32. Which of the following best describes the purpose of the @FindBys annotation? A) Locate a single element by multiple criteria (AND) B) Locate a list of elements using a single locator C) Locate elements using a CSS selector only D) Apply a timeout to element initialization Answer: A Explanation: @FindBys allows chaining multiple @FindBy definitions, requiring all criteria to match (logical AND). Question 33. In Selenium, which command would you use to simulate pressing the ENTER key in an input field? A) element.sendKeys(Keys.ENTER);
B) element.click(); C) element.submit(); D) element.sendKeys("\n"); Answer: A Explanation: Keys.ENTER is part of the Selenium Keys enum and accurately represents the ENTER keystroke. Question 34. What is the main advantage of using headless browsers in CI pipelines? A) They provide a visual UI for debugging B) They consume less memory and run faster without a GUI C) They support all browser extensions automatically D) They eliminate the need for WebDriver binaries Answer: B Explanation: Headless mode runs the browser without rendering a UI, reducing resource usage and speeding up test execution. Question 35. Which Java collection allows fast look-up of elements by a unique key? A) ArrayList B) LinkedList C) HashMap D) Stack Answer: C Explanation: HashMap provides O(1) average time complexity for key-based retrieval. Question 36. Which Selenium command is used to switch to a newly opened browser tab? A) driver.switchTo().newWindow(WindowType.TAB); B) driver.navigate().toNewTab(); C) driver.switchTo().window(handle);
Explanation: Headless mode is enabled by adding the --headless argument to ChromeOptions and passing it to the driver constructor. Question 40. Which of the following statements about implicit and explicit waits is true? A) Implicit wait can be set per element, explicit wait cannot B) Explicit wait overrides implicit wait for the duration of the wait C) Implicit wait is applied globally and can cause longer test times if overused D) Both waits are mutually exclusive and cannot be used together Answer: C Explanation: Implicit wait applies to all element searches; setting a high value can unnecessarily delay every find operation. Question 41. In Java, which access modifier makes a class member visible only within its own package? A) private B) protected C) default (package-private) D) public Answer: C Explanation: When no modifier is specified, the member has package-private visibility, accessible only within the same package. Question 42. Which Selenium method is used to retrieve the title of the current page? A) driver.getTitle(); B) driver.title(); C) driver.getPageTitle(); D) driver.fetchTitle(); Answer: A Explanation: getTitle() returns the title string of the active browser window.
Question 43. What is the purpose of the @BeforeClass annotation in a JUnit test class? A) Runs before each test method B) Runs once before any test method in the class, typically for expensive setup C) Marks a method as a test case D) Executes after all test methods have completed Answer: B Explanation: @BeforeClass (or @BeforeAll in JUnit 5) is used for one-time initialization shared across tests. Question 44. Which of these Selenium commands is used to navigate forward in the browser history? A) driver.navigate().forward(); B) driver.back(); C) driver.history().forward(); D) driver.navigate().next(); Answer: A Explanation: navigate().forward() moves the browser to the next page in its history stack. Question 45. Which exception is thrown when an element previously found becomes stale because the DOM has been refreshed? A) NoSuchElementException B) StaleElementReferenceException C) ElementNotInteractableException D) TimeoutException Answer: B Explanation: StaleElementReferenceException indicates that the reference is no longer valid after a DOM change. Question 46. In the Page Object Model, what is the typical naming convention for a method that performs a login action? A) loginUser()
C) empty D) static Answer: A Explanation: void specifies that a method returns no value. Question 50. Which Selenium command is used to close only the current browser window? A) driver.quit(); B) driver.close(); C) driver.shutdown(); D) driver.exit(); Answer: B Explanation: close() shuts the window that WebDriver is currently controlling, leaving other windows open. Question 51. What does the @DataProvider annotation in TestNG (often used alongside JUnit) provide? A) Parallel execution of tests B) Suppression of test failures C) Parameterized test data to a test method D) Automatic screenshot capture on failure Answer: C Explanation: @DataProvider supplies a set of arguments for a test method, enabling data-driven testing. Question 52. Which of the following is a valid way to locate an element using XPath that selects a button with text “Submit”? A) //button[text()='Submit'] B) //button[@value='Submit'] C) //button[contains(@class,'submit')] D) //button[.='Submit'] Answer: A
Explanation: text() retrieves the exact visible text of the element; the XPath selects a button whose text equals “Submit”. Question 53. In Selenium, which method returns a list of all options within a `` element? A) select.getOptions(); B) select.getAllOptions(); C) select.getChoices(); D) select.getElements(); Answer: A Explanation: The Select class provides getOptions() which returns a List of all `
Question 59. Which JUnit annotation is used to indicate that a method should be executed after each test method? A) @After B) @AfterEach C) @AfterMethod D) @TearDown Answer: A (JUnit 4) / B (JUnit 5) – Since the question does not specify version, the classic answer is @After. Explanation: @After runs after every @Test method, allowing cleanup of test-specific resources. Question 60. What does the driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30)); command do? A) Waits up to 30 seconds for the page to finish loading before throwing an error B) Sets an implicit wait of 30 seconds for element searches C) Delays test execution by 30 seconds after each page load D) Limits the time for JavaScript execution to 30 seconds Answer: A Explanation: pageLoadTimeout defines the maximum time to wait for a page load to complete. Question 61. Which of the following best describes the “Fluent Interface” pattern used by Selenium’s Actions class? A) Methods return void to enforce sequential calls B) Methods return the same object, allowing method chaining C) Methods require explicit callback functions D) Methods are static and cannot be overridden Answer: B Explanation: The fluent interface returns the same Actions instance, enabling chained calls like new Actions(driver).moveToElement(e).click().perform();.
Question 62. In Java, which keyword is used to inherit an abstract method implementation from a superclass? A) abstract B) implements C) extends D) super Answer: C Explanation: A subclass extends its abstract superclass and must provide implementations for abstract methods. Question 63. Which Selenium command would you use to verify that a checkbox is selected? A) element.isSelected(); B) element.isChecked(); C) element.getAttribute("checked"); D) element.isEnabled(); Answer: A Explanation: isSelected() returns true when a checkbox or radio button is currently selected. Question 64. What is the primary purpose of the WebDriverEventListener interface? A) To provide custom logging and actions before/after WebDriver events B) To replace the need for explicit waits C) To manage browser windows automatically D) To generate HTML test reports Answer: A Explanation: Implementing WebDriverEventListener allows developers to intercept WebDriver events such as click, navigation, and exception handling. Question 65. Which of the following is a valid way to locate an element by its CSS class “btn-primary” using Selenium? A) By.cssSelector(".btn-primary")