





















































































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) Selenium WebDriver B) Selenium Grid C) Selenium IDE D) Selenium RC Answer: C Explanation: Selenium IDE is a browser extension that records user interactions and generates test scripts automatically. Question 2. In the Selenium architecture, which protocol is used by WebDriver to communicate with browser drivers as per the W3C standard? A) SOAP B) JSON Wire Protocol C) W3C WebDriver Protocol D) HTTP REST Answer: C Explanation: The W3C WebDriver Protocol is the current standard for communication between Selenium language bindings and browser drivers. Question 3. Which HTML attribute uniquely identifies an element for Selenium locators and is most efficient to use? A) class B) name C) id D) title Answer: C
Explanation: The id attribute is unique within the DOM, making it the fastest and most reliable locator. Question 4. Which of the following is a disadvantage of using absolute XPath? A) It is faster than CSS selectors. B) It breaks when the DOM hierarchy changes. C) It can locate elements without attributes. D) It works across all browsers. Answer: B Explanation: Absolute XPath depends on the full path from the root, so any change in the DOM structure will invalidate the locator. Question 5. What does the Selenium WebDriverWait class primarily handle? A) Implicit waiting for the entire page load. B) Explicit waiting for a specific condition. C) Thread.sleep based waiting. D) Global timeout configuration. Answer: B Explanation: WebDriverWait is used for explicit waits, allowing the script to wait for a particular condition before proceeding. Question 6. Which method checks whether a checkbox element is currently selected? A) isDisplayed() B) isEnabled() C) isSelected() D) getAttribute("checked")
C) driver.exit() D) driver.shutdown() Answer: B Explanation: driver.close() closes the active window, while driver.quit() ends the entire WebDriver session. Question 10. In Selenium Grid, what is the role of the Hub? A) Executes test scripts on remote machines. B) Stores test data. C) Manages and routes test requests to Nodes. D) Generates HTML reports. Answer: C Explanation: The Hub receives test requests and distributes them to registered Nodes based on desired capabilities. Question 11. Which of the following statements about implicit waits is true? A) They apply to a single element only. B) They are set once and remain for the lifetime of the WebDriver instance. C) They override explicit waits. D) They pause the test for a fixed time regardless of element state. Answer: B Explanation: Implicit waits are globally applied and remain active for the WebDriver session unless changed. Question 12. Which Selenium method retrieves the current page’s title? A) driver.getPageTitle()
B) driver.getTitle() C) driver.title() D) driver.getPageName() Answer: B Explanation: driver.getTitle() returns the title of the current page. Question 13. Which Java annotation is used in TestNG to denote a method that should run before any test methods in a class? A) @BeforeClass B) @BeforeMethod C) @BeforeTest D) @BeforeSuite Answer: A Explanation: @BeforeClass runs once before any test methods in the class are executed. Question 14. Which of the following is an advantage of using the Page Object Model (POM)? A) Test scripts become longer. B) Locators are duplicated across tests. C) Improves maintainability by separating page structure from test logic. D) Reduces code readability. Answer: C Explanation: POM encapsulates page elements and actions, making tests easier to maintain and read.
Explanation: The Actions class provides methods like dragAndDrop, moveToElement, and sendKeys. Question 18. What does the Selenium fluentWait method allow you to customize? A) The total timeout only. B) The polling interval and ignored exceptions. C) The browser’s page load strategy. D) The WebDriver’s implicit wait. Answer: B Explanation: FluentWait lets you set the timeout, polling frequency, and specify which exceptions to ignore. Question 19. 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: driver.switchTo().frame(String nameOrId) switches context to the iframe identified by name or id. Question 20. In Selenium, which method returns the value of a specified attribute of a WebElement? A) getText() B) getAttribute(String name) C) getProperty(String name)
D) getValue() Answer: B Explanation: getAttribute fetches the current value of an element’s attribute. Question 21. Which of the following is true about the Selenium WebDriver interface? A) It can only be used with Java. B) It provides methods to interact with the browser’s UI. C) It does not support navigation commands. D) It is deprecated in favor of Selenium RC. Answer: B Explanation: WebDriver defines methods for navigating, locating elements, and interacting with the browser. Question 22. Which Selenium command would you use to retrieve the HTML source of the current page? A) driver.getPageSource() B) driver.getSource() C) driver.pageSource() D) driver.fetchHTML() Answer: A Explanation: driver.getPageSource() returns the complete DOM source as a string. Question 23. Which of the following best describes the purpose of @FindBy annotation in Page Factory? A) To define test data. B) To locate WebElements at runtime using specified strategies.
B) It provides methods to interact with elements such as click and sendKeys. C) It cannot be refreshed once located. D) It automatically handles stale element references. Answer: B Explanation: WebElement defines actions like click(), sendKeys(), clear(), etc. Question 27. Which of the following Selenium commands will wait until an element is visible before proceeding? A) driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); B) new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("id"))); C) Thread.sleep(10000); D) driver.wait(10); Answer: B Explanation: ExpectedConditions.visibilityOfElementLocated explicitly waits for element visibility. Question 28. What is the primary purpose of Selenium’s EventFiringWebDriver? A) To execute JavaScript. B) To capture screenshots automatically. C) To register event listeners for logging or debugging. D) To manage multiple browser windows. Answer: C Explanation: EventFiringWebDriver allows attaching listeners that respond to WebDriver events.
Question 29. Which of the following is the correct way to initialize a ChromeDriver with custom options in Java? A) ChromeOptions options = new ChromeOptions(); options.addArguments("--headless"); WebDriver driver = new ChromeDriver(options); B) ChromeDriver driver = new ChromeDriver(); driver.setOptions("--headless"); C) WebDriver driver = new ChromeDriver(); driver.addArguments("--headless"); D) ChromeOptions options = new ChromeOptions(); WebDriver driver = new ChromeDriver(); options.addArguments("--headless"); Answer: A Explanation: ChromeOptions must be passed to the ChromeDriver constructor to apply arguments like headless mode. Question 30. Which Selenium command is used to retrieve the current URL of the page? A) driver.getCurrentUrl() B) driver.getUrl() C) driver.getPageUrl() D) driver.currentUrl() Answer: A Explanation: driver.getCurrentUrl() returns the URL of the page currently loaded in the browser. Question 31. In Selenium, which of the following is NOT a valid way to locate an element? A) By.id B) By.xpath C) By.cssSelector D) By.htmlTag Answer: D
D) Rely on element text that changes frequently. Answer: C Explanation: Stable custom attributes (data-test-id, data-qa) are less likely to change, providing reliable locators. Question 35. Which TestNG annotation is used to specify that a method should run after all tests in the suite have completed? A) @AfterSuite B) @AfterTest C) @AfterClass D) @AfterMethod Answer: A Explanation: @AfterSuite runs once after all tests in the entire suite finish. Question 36. In Selenium, which method can be used to switch focus to a newly opened browser tab? A) driver.switchTo().window(driver.getWindowHandles().iterator().next()); B) driver.switchTo().tab(); C) driver.switchTo().newWindow(); D) driver.switchTo().window("newTab"); Answer: A Explanation: getWindowHandles() returns a set of window handles; iterating to the new handle and switching to it changes focus. Question 37. Which of the following statements about Selenium implicit waits is FALSE? A) They are applied to every element find operation.
B) They can be overridden by explicit waits. C) They cause the driver to poll the DOM for the specified time. D) They only affect element visibility checks. Answer: D Explanation: Implicit waits affect the search for elements regardless of visibility; they do not specifically wait for visibility. Question 38. Which of the following is the correct way to define a TestNG data provider? A) @DataProvider(name = "loginData") public Object[][] getData() { … } B) @DataProvider public Object[][] loginData() { … } C) @DataProvider(name = "loginData") public void getData() { … } D) @DataProvider public void loginData() { … } Answer: A Explanation: The method must return a two‑dimensional Object array and be annotated with @DataProvider(name="…"). Question 39. Which Selenium command would you use to clear the contents of a text input field before entering new data? A) element.clear(); B) element.delete(); C) element.empty(); D) element.reset(); Answer: A Explanation: clear() removes any existing text from an input or textarea element.
Explanation: getWindowHandles() returns a Set of window handles; its size indicates the number of windows. Question 43. What is the purpose of the @BeforeMethod annotation in TestNG? A) To run a method once before the entire suite. B) To execute a method before each test method in a class. C) To set up the test environment after all tests. D) To provide data to a test method. Answer: B Explanation: @BeforeMethod runs before every individual test method, preparing preconditions. Question 44. Which Selenium command is used to scroll the page until a specific element is in view? A) driver.scrollTo(element); B) ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", element); C) driver.moveToElement(element); D) driver.scrollIntoView(element); Answer: B Explanation: scrollIntoView JavaScript executed via JavascriptExecutor brings the element into the viewport. Question 45. Which of the following is true about Selenium’s RemoteWebDriver? A) It can only control local browsers. B) It communicates with a Selenium Server over HTTP. C) It does not support any browser capabilities.
D) It replaces ChromeDriver entirely. Answer: B Explanation: RemoteWebDriver sends commands to a Selenium Server (or Grid node) via HTTP. Question 46. Which of the following best describes a “stale element reference” exception? A) The element was never found. B) The element is hidden. C) The DOM has changed since the element was located. D) The element is disabled. Answer: C Explanation: After a page refresh or DOM update, previously retrieved WebElement objects become stale. Question 47. Which Selenium command is used to add a custom header to an HTTP request? A) driver.addHeader("key","value"); B) Not possible directly; must use a proxy or browser extension. C) driver.setHeader("key","value"); D) driver.manage().addHeader("key","value"); Answer: B Explanation: Selenium does not provide an API to modify HTTP headers; a proxy or browser- specific solution is required. Question 48. Which of the following is a recommended way to handle a dropdown that allows multiple selections? A) Use the Select class and call selectByVisibleText for each option.
Question 51. Which of the following statements about Selenium Grid’s node configuration file is correct? A) It must contain the hub’s IP address and port. B) It only lists the browsers to be used, not the hub address. C) It is optional; nodes can start without it. D) It defines test data for the node. Answer: A Explanation: The node config (nodeConfig.json) includes the hub’s URL, max sessions, and browser capabilities. Question 52. Which Selenium command would you use to wait for a page to finish loading completely? A) driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); B) new WebDriverWait(driver, 30).until(ExpectedConditions.pageLoadComplete()); C) driver.waitForPageLoad(); D) Thread.sleep(30000); Answer: A Explanation: pageLoadTimeout sets the maximum time WebDriver will wait for a page to load before throwing an error. Question 53. Which of the following is a correct way to instantiate a Firefox driver with a custom profile? A) FirefoxOptions options = new FirefoxOptions(); options.setProfile(new FirefoxProfile()); WebDriver driver = new FirefoxDriver(options); B) FirefoxDriver driver = new FirefoxDriver(); driver.setProfile(new FirefoxProfile()); C) WebDriver driver = new FirefoxDriver(new FirefoxProfile());
D) FirefoxOptions options = new FirefoxOptions(); WebDriver driver = new FirefoxDriver(); options.setProfile(new FirefoxProfile()); Answer: A Explanation: FirefoxOptions allows setting a FirefoxProfile before creating the FirefoxDriver. Question 54. Which of the following is the most appropriate use of the @DataProvider feature in TestNG? A) To supply different sets of input data to a single test method. B) To configure WebDriver capabilities. C) To define test suite order. D) To execute tests in parallel. Answer: A Explanation: @DataProvider returns multiple data sets that a test method can consume, enabling data‑driven testing. Question 55. Which Selenium method can be used to retrieve the value of a cookie by its name? A) driver.manage().getCookieNamed("sessionId"); B) driver.manage().findCookie("sessionId"); C) driver.getCookie("sessionId"); D) driver.manage().retrieveCookie("sessionId"); Answer: A Explanation: getCookieNamed returns the Cookie object for the specified name. Question 56. Which of the following best describes the purpose of the DesiredCapabilities class in Selenium? A) To define the operating system only.