Docsity

Certified Selenium Professional Practice Exam, Exams of Technology

Toggle sidebar
bg1
Certified Selenium Professional Practice
Exam
**Question 1. Which component of Selenium WebDriver architecture directly translates
WebDriver commands into actions performed by a specific browser?**
A) Client Library
B) JSON Wire Protocol
C) Browser Driver
D) Browser
Answer: C
Explanation: The Browser Driver (e.g., chromedriver, geckodriver) receives commands over the
WebDriver protocol and interacts with the browser’s native API to perform actions.
**Question 2. What is the main advantage of the W3C WebDriver protocol over the legacy JSON
Wire Protocol?**
A) Supports only Chrome browsers
B) Provides a standardized, vendor‑agnostic command set
C) Removes the need for DesiredCapabilities
D) Enables execution of JavaScript without a driver
Answer: B
Explanation: The W3C protocol defines a uniform standard that all browser vendors implement,
reducing inconsistencies and improving cross‑browser compatibility.
**Question 3. In Selenium 4, which class replaces DesiredCapabilities for configuring Chrome
options in a W3C‑compliant way?**
A) ChromeOptions
B) FirefoxOptions
C) EdgeOptions
D) SafariOptions
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c

Partial preview of the text

Download Certified Selenium Professional Practice Exam and more Exams Technology in PDF only on Docsity!

Exam

Question 1. Which component of Selenium WebDriver architecture directly translates WebDriver commands into actions performed by a specific browser? A) Client Library B) JSON Wire Protocol C) Browser Driver D) Browser Answer: C Explanation: The Browser Driver (e.g., chromedriver, geckodriver) receives commands over the WebDriver protocol and interacts with the browser’s native API to perform actions. Question 2. What is the main advantage of the W3C WebDriver protocol over the legacy JSON Wire Protocol? A) Supports only Chrome browsers B) Provides a standardized, vendor‑agnostic command set C) Removes the need for DesiredCapabilities D) Enables execution of JavaScript without a driver Answer: B Explanation: The W3C protocol defines a uniform standard that all browser vendors implement, reducing inconsistencies and improving cross‑browser compatibility. Question 3. In Selenium 4, which class replaces DesiredCapabilities for configuring Chrome options in a W3C‑compliant way? A) ChromeOptions B) FirefoxOptions C) EdgeOptions D) SafariOptions

Exam

Answer: A Explanation: ChromeOptions implements the W3C Options interface, allowing you to set capabilities such as arguments, extensions, and experimental options. Question 4. Which WebDriver method navigates the browser forward in its history? A) driver.navigate().back() B) driver.navigate().forward() C) driver.navigate().refresh() D) driver.navigate().to() Answer: B Explanation: navigate().forward() moves the browser one step forward in the session’s history stack. Question 5. How can you scroll to the bottom of a page using JavascriptExecutor? A) ((JavascriptExecutor)driver).executeScript("window.scrollTo(0, document.body.scrollHeight)"); B) driver.scrollToBottom(); C) ((JavascriptExecutor)driver).executeScript("document.body.scrollTop = 0"); D) driver.manage().window().maximize(); Answer: A Explanation: The JavaScript window.scrollTo with document.body.scrollHeight scrolls to the page’s maximum vertical length. Question 6. Which JavaScript snippet sets the value of an input element identified by its ID to “Selenium”?

Exam

Answer: A Explanation: getWindowHandles() provides a Set containing the unique identifiers for each open browser window or tab. Question 9. How do you switch Selenium’s focus to a window with a specific title “Dashboard”? A) for (String handle : driver.getWindowHandles()) { driver.switchTo().window(handle); if (driver.getTitle().equals("Dashboard")) break; } B) driver.switchTo().window("Dashboard"); C) driver.switchTo().frame("Dashboard"); D) driver.navigate().to("Dashboard"); Answer: A Explanation: Iterate over each window handle, switch to it, and compare the title; break when the desired title matches. Question 10. Which method switches Selenium’s context back to the main document after working inside an iframe? A) driver.switchTo().defaultContent(); B) driver.switchTo().parentFrame(); C) driver.switchTo().frame(0); D) driver.navigate().back(); Answer: A Explanation: defaultContent() returns the focus to the top‑level browsing context, exiting any nested frames. Question 11. What is the effect of setting an implicit wait of 10 seconds? A) Every element lookup will wait up to 10 seconds before throwing NoSuchElementException.

Exam

B) The test will pause for exactly 10 seconds before each step. C) Only the first element lookup uses the wait. D) It disables explicit waits. Answer: A Explanation: Implicit wait tells WebDriver to poll the DOM for the specified time when trying to locate elements. Question 12. Which ExpectedCondition waits until a specific element becomes clickable? A) ExpectedConditions.elementToBeClickable(By locator) B) ExpectedConditions.visibilityOfElementLocated(By locator) C) ExpectedConditions.presenceOfElementLocated(By locator) D) ExpectedConditions.stalenessOf(element) Answer: A Explanation: elementToBeClickable checks both visibility and enabled state, ensuring the element can be clicked. Question 13. How can you configure a FluentWait to ignore NoSuchElementException and poll every 500 ms? A) new FluentWait<>(driver).ignoring(NoSuchElementException.class).pollingEvery(Duration.ofMillis( 0)).withTimeout(Duration.ofSeconds(30)); B) new FluentWait<>(driver).withTimeout(30).pollingEvery(500); C) new FluentWait<>(driver).ignoreAllExceptions(); D) new FluentWait<>(driver).withException(NoSuchElementException.class); Answer: A Explanation: FluentWait provides methods to specify the timeout, polling interval, and exception types to ignore.

Exam

Answer: B Explanation: The following-sibling axis returns nodes that share the same parent and appear after the context node. Question 17. How would you write an XPath that selects a button whose text starts with “Submit” regardless of surrounding whitespace? A) //button[starts-with(normalize-space(.), 'Submit')] B) //button[contains(text(),'Submit')] C) //button[starts-with(text(),'Submit')] D) //button[normalize-space()='Submit'] Answer: A Explanation: normalize-space(.) trims leading/trailing whitespace and collapses internal spaces, then starts-with checks the prefix. Question 18. Which CSS selector matches any `` element with a type attribute ending in “password”? A) input[type$='password'] B) input[type*='password'] C) input[type^='password'] D) input[type='password'] Answer: A Explanation: The $= attribute selector matches the suffix of an attribute value. Question 19. In a dynamic HTML table, how can you locate the cell that contains the text “Active” in the column with header “Status”? A) //th[text()='Status']/ancestor::table//td[text()='Active']

Exam

B) //table//tr[td[text()='Active']]/td[1] C) //table//tr[th='Status']//td='Active' D) //td[contains(@class,'status') and text()='Active'] Answer: A Explanation: Locate the header cell, move up to the table element, then search for a with the desired text within that table. **Question 20. Which technique is required to interact with elements inside a Shadow DOM?** A) driver.switchTo().shadowRoot(); B) ((JavascriptExecutor)driver).executeScript("return arguments[0].shadowRoot", hostElement); C) driver.findElement(By.shadowDom(...)); D) Shadow DOM elements are automatically accessible. Answer: B Explanation: Selenium does not have native Shadow DOM support; you must retrieve the shadow root via JavaScript and then locate elements inside it. **Question 21. How can you locate an SVG element using XPath?** A) //[local-name()='svg']//[local-name()='circle'] B) //svg/circle C) //*[name()='circle'] D) //svg//circle[@id] Answer: A Explanation: SVG elements belong to a different XML namespace; using local-name() bypasses namespace issues. Question 22. Which Actions method simulates pressing the SHIFT key while typing “hello”?

Exam

Explanation: Selenium provides both a high‑level dragAndDrop method and a low‑level sequence using clickAndHold, moveToElement, and release. Question 25. In the Page Object Model, what is the primary purpose of a BasePage class? A) To store test data. B) To contain common WebDriver utilities and shared element interactions for all pages. C) To define test steps. D) To generate HTML reports. Answer: B Explanation: A BasePage abstracts reusable methods (e.g., wait utilities, navigation) that child page classes inherit, promoting DRY principles. Question 26. Which TestNG annotation is used to supply data to a test method from an external CSV file? A) @DataProvider B) @Parameters C) @Factory D) @CsvSource Answer: A Explanation: @DataProvider can read CSV content programmatically and feed the data sets to the test method. Question 27. In Cucumber, which keyword defines a reusable set of steps that run before every scenario in a feature file? A) Scenario Outline B) Background

Exam

C) Given D) @Before Answer: B Explanation: The Background section contains steps that execute before each scenario within the same feature. Question 28. Which logging framework is recommended for thread‑safe logging in a parallel Selenium test suite? A) java.util.logging B) Log4j C) System.out.println D) Apache Commons Logging Answer: B Explanation: Log4j2 supports asynchronous, thread‑safe logging and can be configured per thread, making it suitable for parallel execution. Question 29. How can you capture a full‑page screenshot in Chrome using Selenium 4? A) ((ChromeDriver)driver).getFullPageScreenshotAs(OutputType.FILE); B) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); C) driver.manage().window().fullscreen(); D) Selenium cannot capture full‑page screenshots. Answer: A Explanation: ChromeDriver implements FullPageScreenshot in Selenium 4, allowing capture of the entire scrollable page.

Exam

Answer: B Explanation: Using a single static WebDriver across threads leads to commands being sent to the wrong browser session, causing flaky results. Question 33. In Selenium Grid 4, which component replaces the older “Hub” concept? A. Router B. Node C. Distributor D. Session Queue Answer: A Explanation: Grid 4 introduces a Router that receives session requests and forwards them to appropriate Nodes, decoupling responsibilities from the legacy Hub. Question 34. Which Docker command is typically used to start a Selenium Grid Node container for Chrome? A) docker run - d - e SE_EVENT_BUS_HOST=hub selenium/node-chrome B) docker start selenium-grid-node-chrome C) docker exec selenium-node chrome --start-grid D) docker compose up node-chrome Answer: A Explanation: The Selenium Docker images accept environment variables like SE_EVENT_BUS_HOST to register the node with the hub/router. Question 35. How can you attach a screenshot to an Allure report from a TestNG listener? A) Allure.addAttachment("Screenshot", "image/png", inputStream, ".png"); B) Reporter.log("");

Exam

C) ExtentReports.attachScreenshot("screenshot.png"); D) Allure.attachFile("screenshot.png"); Answer: A Explanation: Allure.addAttachment registers binary data (e.g., a screenshot) with the report, specifying MIME type and file extension. Question 36. Which Jenkins plugin enables publishing of ExtentReports after a Selenium test run? A) Allure Jenkins Plugin B) HTML Publisher Plugin C) JUnit Plugin D) Performance Plugin Answer: B Explanation: The HTML Publisher plugin can archive and display any generated HTML report, including ExtentReports. Question 37. What is a primary benefit of running Selenium tests in headless mode? A) Tests run faster because no UI is rendered. B) Browser UI is visible for debugging. C) It enables interaction with OS dialogs. D) It disables JavaScript execution. Answer: A Explanation: Headless browsers omit the graphical rendering pipeline, reducing resource consumption and speeding up execution. Question 38. Which capability enables Chrome to run in headless mode via Selenium?

Exam

Question 41. Which HTTP client library is commonly used with Rest‑Assured for making API calls in a Selenium workflow? A) Apache HttpClient B) java.net.URLConnection C) OkHttp D) Rest‑Assured itself wraps Apache HttpClient internally. Answer: D Explanation: Rest‑Assured abstracts HTTP communication and internally uses Apache HttpClient, allowing concise API requests. Question 42. How can BrowserMob Proxy be used together with Selenium? A) To capture network traffic (HAR) while tests run. B) To replace Selenium’s WebDriver. C) To execute JavaScript in the browser. D) To manage test data files. Answer: A Explanation: BrowserMob Proxy starts a proxy server that Selenium can route traffic through, enabling capture and analysis of HTTP requests/responses. Question 43. Which TestNG annotation ensures that a method runs after every test method, regardless of its outcome? A) @AfterMethod(alwaysRun = true) B) @AfterTest C) @AfterSuite D) @AfterClass Answer: A

Exam

Explanation: Setting alwaysRun = true forces the annotated method to execute even if the test method fails or is skipped. Question 44. In Selenium 4, which interface provides the method getCapabilities() to retrieve the actual capabilities of a running session? A) Capabilities B) RemoteWebDriver C) WebDriver.Options D) TakesScreenshot Answer: B Explanation: RemoteWebDriver implements getCapabilities(), returning a Capabilities object that reflects the session’s negotiated settings. Question 45. What does the Selenium command driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); enforce? A) The maximum time to wait for a page to finish loading before throwing a TimeoutException. B) The implicit wait for element location. C) The script execution timeout for JavaScript. D) The duration of explicit waits. Answer: A Explanation: pageLoadTimeout sets the limit for the entire page load operation, after which Selenium aborts with a timeout error. Question 46. Which ExpectedCondition can be used to wait until an alert is present? A) ExpectedConditions.alertIsPresent() B) ExpectedConditions.visibilityOfElementLocated(By.alert)

Exam

B) A test case identifier. C) A network port used by the hub. D) A thread pool inside the driver. Answer: A Explanation: A slot represents a single browser instance (with its capabilities) that a node can allocate for a test session. Question 50. Which Maven dependency is required to use the Selenium Actions class? A) selenium-java B) selenium-api C) selenium-server D) selenium-remote-driver Answer: A Explanation: The selenium-java artifact bundles the core client library, including the Actions class. Question 51. How can you configure TestNG to generate a JUnit XML report in addition to its default HTML report? A) Set outputDirectory in the TestNG XML suite. B) Add C) Use the `testng-results.xml` file generated automatically. D) Include Answer: D Explanation: Adding XMLReporter as a listener instructs TestNG to produce JUnit‑compatible XML output.

Exam

Question 52. Which Selenium command scrolls an element into view using JavaScript? A) ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", element); B) driver.scrollTo(element); C) element.scrollIntoView(); D) driver.manage().window().scrollTo(element); Answer: A Explanation: scrollIntoView called via JavascriptExecutor brings the element into the viewport. Question 53. What is the purpose of the @FindBy annotation in PageFactory? A) To define the test data source. B) To locate WebElements lazily when they are first accessed. C) To configure the browser capabilities. D) To generate HTML reports. Answer: B Explanation: @FindBy together with PageFactory.initElements creates proxy WebElements that are located only when used, improving performance. Question 54. Which method in TestNG allows you to skip a test dynamically based on a condition? A) throw new SkipException("reason"); B) Assert.skip(); C) TestNG.skipTest(); D) @SkipIf(condition) Answer: A