







































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Covers Selenium WebDriver, Java programming, test automation frameworks, execution strategies, reporting, and software testing principles.
Typology: Exams
1 / 47
This page cannot be seen from the preview
Don't miss anything!








































Question 1. Which Selenium WebDriver method is used to navigate to a specific URL? A) driver.get() B) driver.open() C) driver.navigate() D) driver.load() Answer: A Explanation: driver.get(String url) loads a web page in the current browser window and waits until the page is fully loaded. Question 2. In Java, which interface must a TestNG test class implement to receive configuration callbacks such as beforeSuite and afterSuite? A) ITestListener B) IInvokedMethodListener C) ITestNGListener D) None; TestNG uses annotations instead of interfaces. Answer: D Explanation: TestNG relies on annotations like @BeforeSuite and @AfterSuite; no interface implementation is required for these callbacks. Question 3. What is the primary advantage of using the Page Object Model (POM) in Selenium automation? A) Reduces the number of test cases needed. B) Centralizes element locators and actions, improving maintainability. C) Eliminates the need for explicit waits. D) Allows tests to run without a browser. Answer: B Explanation: POM encapsulates page elements and interactions in separate classes, making updates easier when UI changes. Question 4. Which of the following locator strategies is generally the fastest in Selenium WebDriver? A) By.id()
B) By.xpath() C) By.cssSelector() D) By.linkText() Answer: A Explanation: Locating by ID is the most efficient because browsers maintain a hash map of IDs for quick access. Question 5. When using Selenium Grid, what role does the hub play? A) Executes test scripts on remote machines. B) Stores test data. C) Manages and routes test requests to registered nodes. D) Generates test reports. Answer: C Explanation: The hub receives test requests and distributes them to appropriate nodes based on capabilities. Question 6. Which Selenium WebDriver method switches control to an iframe identified by its name attribute? A) driver.switchTo().frame("frameName") B) driver.switchTo().frameByName("frameName") C) driver.switchTo().frameById("frameName") D) driver.switchTo().iframe("frameName") Answer: A Explanation: switchTo().frame(String nameOrId) switches context to the iframe using its name or ID. Question 7. In Java, which keyword ensures that a variable cannot be reassigned after its initial assignment? A) static B) final C) const D) immutable
Answer: D Explanation: setCapability is used with DesiredCapabilities, not directly on ChromeOptions; the correct method is options.setCapability("..."). Question 11. Which Java collection is most appropriate for storing test data that must maintain insertion order and allow duplicate entries? A) HashSet B) LinkedHashSet C) ArrayList D) TreeMap Answer: C Explanation: ArrayList preserves insertion order and permits duplicates, fitting the described requirement. Question 12. In Selenium, which method is used to retrieve the text of a web element? A) element.getValue() B) element.getText() C) element.text() D) element.retrieveText() Answer: B Explanation: getText() returns the visible (inner) text of the element. Question 13. Which of the following statements about Selenium’s Actions class is TRUE? A) It can only perform mouse actions. B) It requires the use of the Builder pattern. C) It supports composite actions like drag-and-drop and keyboard shortcuts. D) It automatically handles alerts. Answer: C Explanation: Actions enables complex user interactions, including mouse and keyboard sequences.
Question 14. What is the default timeout for a Selenium WebDriver explicit wait created with new WebDriverWait(driver, Duration.ofSeconds(30))? A) 10 seconds B) 30 seconds C) No timeout; it waits indefinitely. D) 5 seconds Answer: B Explanation: The duration passed to WebDriverWait defines the maximum wait time. Question 15. Which Maven scope should be used for Selenium dependencies that are required only at test execution time? A) compile B) provided C) test D) runtime Answer: C Explanation: The test scope includes dependencies only during the test phase. Question 16. In TestNG, what does the attribute dependsOnMethods achieve? A) Runs the test in parallel. B) Skips the test if the specified methods fail. C) Executes the test before the listed methods. D) Marks the test as optional. Answer: B Explanation: dependsOnMethods makes a test dependent on the success of other methods; if they fail, the dependent test is skipped. Question 17. Which of the following WebDriver commands can be used to capture a screenshot and store it as a file?
C) StaleElementReferenceException D) TimeoutException Answer: B Explanation: ElementNotInteractableException (formerly ElementNotVisibleException) is thrown when the element cannot be interacted with. Question 21. Which of the following is a correct way to assert that a string contains a specific substring using TestNG? A) Assert.assertTrue(actual.contains(expected)); B) Assert.assertEquals(actual, expected); C) Assert.assertFalse(actual.contains(expected)); D) Assert.assertNull(actual); Answer: A Explanation: assertTrue with the condition checks for substring presence. Question 22. What does the Selenium command driver.switchTo().alert().accept(); accomplish? A) Dismisses a confirmation dialog. B) Accepts (clicks OK on) a JavaScript alert. C) Retrieves the text of an alert. D) Sends keys to a prompt alert. Answer: B Explanation: accept() confirms the alert, equivalent to clicking OK. Question 23. Which of the following is the most appropriate way to handle a dropdown `` element in Selenium? A) driver.findElement(By.id("mySelect")).click(); B) new Select(driver.findElement(By.id("mySelect"))).selectByVisibleText("Option"); C) driver.executeScript("document.getElementById('mySelect').value='Option'"); D) driver.findElement(By.xpath("//option[text()='Option']")).click();
Answer: B Explanation: Selenium’s Select class provides methods like selectByVisibleText for `` elements. Question 24. In Java, which annotation indicates that a method should be run once before any test methods in the entire suite? A) @BeforeClass B) @BeforeTest C) @BeforeSuite D) @BeforeMethod Answer: C Explanation: @BeforeSuite runs once before all tests in the suite. Question 25. Which of the following statements about Selenium’s implicitlyWait and explicitWait is TRUE? A) Implicit wait applies to the entire driver session; explicit wait is applied per condition. B) Both waits can be used together without any side effects. C) Implicit wait is faster than explicit wait. D) Explicit wait can only be used with JavaScript alerts. Answer: A Explanation: Implicit wait is a global setting; explicit wait is defined for specific conditions. Question 26. Which Selenium WebDriver method is used to close only the current browser window? A) driver.quit() B) driver.close() C) driver.shutdown() D) driver.exit() Answer: B Explanation: driver.close() closes the active window, while driver.quit() ends the entire session.
A) NoSuchElementException B) StaleElementReferenceException C) ElementNotInteractableException D) InvalidSelectorException Answer: B Explanation: StaleElementReferenceException occurs when the element reference becomes outdated after page changes. Question 31. Which TestNG attribute controls the order in which test methods are executed? A) priority B) order C) sequence D) dependsOnMethods Answer: A Explanation: The priority attribute (lower numbers run first) determines execution order. Question 32. In Selenium, which method would you use to retrieve the value of an attribute named "data-id" from a WebElement? A) element.getAttribute("data-id") B) element.getProperty("data-id") C) element.getCssValue("data-id") D) element.getText("data-id") Answer: A Explanation: getAttribute returns the value of any attribute of the element. Question 33. Which of the following statements about driver.navigate().back() is correct? A) It reloads the current page. B) It simulates the browser's back button. C) It navigates forward in the history.
D) It closes the current tab. Answer: B Explanation: navigate().back() moves the browser back one entry in its history stack. Question 34. What is the primary purpose of the @DataProvider annotation in TestNG? A) To supply multiple sets of parameters to a single test method. B) To define the test suite structure. C) To configure parallel execution. D) To generate test reports. Answer: A Explanation: @DataProvider methods return Object[][], allowing a test to run with various data sets. Question 35. Which Maven plugin is commonly used to generate HTML test reports for TestNG? A) maven-surefire-plugin B) maven-failsafe-plugin C) maven-site-plugin with testng-report plugin D) maven-compiler-plugin Answer: C Explanation: The maven-site-plugin together with the testng-report plugin creates TestNG HTML reports. Question 36. In Selenium, what does the driver.manage().window().maximize(); command do? A) Opens a new browser window. B) Sets the browser to full-screen mode (OS-level). C) Maximizes the current browser window to the screen size. D) Changes the viewport size to 1920x1080. Answer: C
Question 40. What is the effect of setting @Test(enabled = false) in a TestNG test method? A) The test will be skipped at runtime. B) The test will run but its results are ignored. C) The test will cause a compilation error. D) The test will be executed in a separate thread. Answer: A Explanation: enabled=false disables the test; TestNG will not execute it. Question 41. Which of the following is the correct way to initialize a FirefoxDriver using WebDriverManager? A) WebDriverManager.firefoxdriver().setup(); WebDriver driver = new FirefoxDriver(); B) WebDriverManager.setupFirefox(); WebDriver driver = new FirefoxDriver(); C) FirefoxDriver driver = new FirefoxDriver(); WebDriverManager.firefoxdriver().configure(); D) WebDriverManager.getFirefox().install(); WebDriver driver = new FirefoxDriver(); Answer: A Explanation: WebDriverManager.firefoxdriver().setup() downloads the driver binary, then instantiate FirefoxDriver. Question 42. In Selenium, which command is used to execute arbitrary JavaScript in the context of the currently loaded page? A) driver.executeScript(...) B) driver.runJavaScript(...) C) driver.invokeScript(...) D) driver.performScript(...) Answer: A Explanation: executeScript(String script, Object... args) runs JavaScript via the JavaScriptExecutor interface.
Question 43. Which TestNG attribute can be used to group test methods for selective execution? A) groups B) category C) suite D) tag Answer: A Explanation: The groups attribute allows tests to be assigned to logical groups and run via include/exclude. Question 44. What does the Selenium ExpectedConditions.elementToBeClickable(By locator) condition check? A) That the element is present in the DOM. B) That the element is visible and enabled such that you can click it. C) That the element has a specific CSS class. D) That the element is selected. Answer: B Explanation: elementToBeClickable ensures visibility and enabled state. Question 45. Which of the following is NOT a valid Selenium WebDriver wait strategy? A) FluentWait B) ImplicitWait C) ExplicitWait D) RandomWait Answer: D Explanation: RandomWait does not exist in Selenium. Question 46. In Java, what is the purpose of the try-with-resources statement when working with Selenium? A) To automatically close WebDriver instances. B) To handle exceptions without a catch block.
C) driver.moveToElement(element); D) driver.actions().scrollTo(element).perform(); Answer: B Explanation: Using JavaScript’s scrollIntoView ensures the element is brought into the viewport. Question 50. Which of the following best describes the difference between assertEquals and assertSame in TestNG? A) assertEquals compares values; assertSame compares object references. B) assertEquals checks if strings are equal ignoring case; assertSame is case-sensitive. C) assertEquals is for primitives; assertSame is for collections. D) There is no difference; they are aliases. Answer: A Explanation: assertEquals checks logical equality via equals(); assertSame verifies that both references point to the exact same object. Question 51. 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. Question 52. In Java, which annotation indicates that a method should be executed once after all tests in a class have run? A) @AfterClass B) @AfterTest C) @AfterSuite D) @AfterMethod
Answer: A Explanation: @AfterClass runs after all @Test methods in the class have finished. Question 53. Which of the following is the correct way to wait for an element to become invisible using Selenium’s ExpectedConditions? A) wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("loader"))); B) wait.until(ExpectedConditions.elementNotVisible(By.id("loader"))); C) wait.until(ExpectedConditions.waitForElementToDisappear(By.id("loader"))); D) wait.until(ExpectedConditions.stalenessOf(By.id("loader"))); Answer: A Explanation: invisibilityOfElementLocated waits until the element is either not present or not visible. Question 54. Which TestNG annotation allows you to specify that a test method should be executed multiple times with different data sets? A) @Parameters B) @DataProvider C) @Factory D) @Test(times=5) Answer: B Explanation: @DataProvider supplies varying inputs to a single test method. Question 55. In Selenium Grid, what does the term “node” refer to? A) The central server that receives test requests. B) A machine that runs one or more browser instances to execute tests. C) A configuration file. D) The database storing test results. Answer: B Explanation: Nodes are remote machines registered with the hub to run tests. Question 56. Which of the following options is used to run Chrome in headless mode with Selenium WebDriver?
Answer: B Explanation: @Parameters reads parameter values defined in testng.xml and passes them to the test method. Question 60. Which of the following statements about Selenium’s driver.manage().timeouts().pageLoadTimeout() is correct? A) It sets the maximum time to wait for a page to load before throwing a TimeoutException. B) It controls the implicit wait for element location. C) It defines the time for JavaScript execution. D) It sets the duration for explicit waits. Answer: A Explanation: pageLoadTimeout specifies how long WebDriver should wait for the page load event. Question 61. In Java, which collection interface guarantees that elements are stored in sorted order? A) List B) Set C) SortedSet D) Queue Answer: C Explanation: SortedSet (e.g., TreeSet) maintains elements in natural order or a comparator-defined order. Question 62. Which Selenium command can be used to simulate pressing the ENTER key on a text input element? A) element.sendKeys(Keys.ENTER); B) element.pressKey(Keys.ENTER); C) element.type(Keys.ENTER); D) element.click(Keys.ENTER); Answer: A
Explanation: sendKeys with Keys.ENTER sends the ENTER keystroke to the element. Question 63. What is the purpose of the @BeforeMethod annotation in TestNG? A) To run a method once before the entire test suite. B) To execute a method before each test method in the class. C) To initialize test data only once. D) To configure the test environment after all tests. Answer: B Explanation: @BeforeMethod runs before every @Test method. Question 64. Which of the following is a valid way to capture console logs from Chrome using Selenium? A) LoggingPreferences logs = new LoggingPreferences(); logs.enable(LogType.BROWSER, Level.ALL); ChromeOptions options = new ChromeOptions(); options.setCapability(CapabilityType.LOGGING_PREFS, logs); WebDriver driver = new ChromeDriver(options); B) driver.getConsoleLogs(); C) driver.manage().logs().getBrowser(); D) ChromeDriver driver = new ChromeDriver(); driver.enableLogging(); Answer: A Explanation: Setting LoggingPreferences via capabilities enables retrieval of browser console logs. Question 65. In TestNG, which attribute of the @Test annotation can be used to set the timeout for a test method? A) timeOut B) duration C) maxTime D) limit Answer: A