








































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
Focuses on browser automation, JavaScript testing frameworks, Selenium integration, automation design, and testing best practices.
Typology: Exams
1 / 48
This page cannot be seen from the preview
Don't miss anything!









































Question 1. Which Selenium command is used to navigate to a URL in JavaScript WebDriver? A) driver.getUrl() B) driver.navigate().to() C) driver.open() D) driver.load() Answer: B Explanation: driver.navigate().to(url) directs the browser to the specified URL; driver.get(url) is also valid but the question asks for the navigation command. Question 2. In Selenium WebDriver with JavaScript, which locator strategy should be used for a button with the text “Submit” when no unique ID or class is available? A) By.id() B) By.css() C) By.xpath() D) By.name() Answer: C Explanation: XPath can locate elements by visible text using //button[text()='Submit'], which is useful when other attributes are not unique. Question 3. What is the default timeout for an implicit wait in Selenium WebDriver if not set explicitly? A) 0 seconds B) 5 seconds C) 10 seconds D) 30 seconds Answer: A Explanation: Implicit wait defaults to 0; you must set it using driver.manage().setTimeouts({ implicit: ms }). Question 4. Which of the following statements about the await keyword in async Selenium tests is true?
A) It can be used only with driver.findElement B) It pauses the test until the promise resolves C) It replaces the need for explicit waits D) It automatically retries failed commands Answer: B Explanation: await pauses execution until the returned promise resolves, making asynchronous code appear synchronous. Question 5. Which method captures a screenshot and returns it as a Base64-encoded string in JavaScript WebDriver? A) driver.takeScreenshot() B) driver.getScreenshotAs('base64') C) driver.saveScreenshot() D) driver.captureScreen() Answer: A Explanation: driver.takeScreenshot() returns a promise that resolves to a Base64 string of the screenshot. Question 6. How can you switch to an iframe identified by the name “contentFrame” in Selenium JavaScript? A) driver.switchTo().frame('contentFrame') B) driver.switchTo().frameByName('contentFrame') C) driver.switchTo().frameElement('contentFrame') D) driver.switchTo().iframe('contentFrame') Answer: A Explanation: driver.switchTo().frame(nameOrId) switches context to the specified iframe. Question 7. Which of the following is NOT a valid capability for Chrome in Selenium WebDriver? A) "goog:chromeOptions" B) "chrome.binary"
Answer: B Explanation: until.elementIsVisible(element) expects a WebElement, so you first locate the element then wait for its visibility. Question 11. Which command is used to execute raw JavaScript in the browser context via Selenium WebDriver? A) driver.runScript() B) driver.executeScript() C) driver.performScript() D) driver.injectScript() Answer: B Explanation: driver.executeScript(script, ...args) runs JavaScript in the page’s context. Question 12. How can you retrieve the current URL of the page in a Selenium test written in JavaScript? A) driver.getCurrentUrl() B) driver.getUrl() C) driver.currentUrl() D) driver.getLocation() Answer: A Explanation: driver.getCurrentUrl() returns a promise that resolves to the current page URL. **Question 13. Which of the following statements about Selenium Grid is FALSE? ** A) It allows parallel execution on multiple browsers. B) It requires a hub and at least one node. C) Nodes can register with the hub dynamically. D) It can only run tests on the same machine as the hub. Answer: D Explanation: Selenium Grid can run tests on remote machines; it is not limited to the hub host.
Question 14. In JavaScript WebDriver, which method is used to accept an alert dialog? A) driver.switchTo().alert().accept() B) driver.alert().accept() C) driver.handleAlert().accept() D) driver.switchTo().acceptAlert() Answer: A Explanation: You must switch to the alert first, then call accept(). Question 15. Which of the following is the correct syntax to upload a file using Selenium WebDriver in JavaScript? A) driver.findElement(By.id('file')).sendKeys('/path/to/file') B) driver.findElement(By.id('file')).upload('/path/to/file') C) driver.uploadFile('/path/to/file') D) driver.findElement(By.id('file')).setFile('/path/to/file') Answer: A Explanation: sendKeys() on a file input element sets the file path for upload. Question 16. What does the driver.manage().deleteAllCookies() command do? A) Clears session storage only B) Deletes all cookies for the current domain C) Clears local storage only D) Resets the browser to default settings Answer: B Explanation: It removes all cookies associated with the current domain. Question 17. Which of the following is the best practice for handling flaky tests due to timing issues? A) Increase implicit wait to 30 seconds globally B) Use explicit waits for specific conditions
Question 21. Which WebDriver command scrolls the page until an element is in view? A) driver.executeScript('arguments[0].scrollIntoView()', element) B) driver.scrollTo(element) C) driver.moveTo(element) D) driver.scrollIntoView(element) Answer: A Explanation: Using JavaScript scrollIntoView via executeScript ensures the element is visible. Question 22. What is the purpose of the --headless flag when launching Chrome via Selenium? A) To run Chrome without a UI, suitable for CI environments B) To disable JavaScript execution C) To open Chrome in incognito mode D) To enable GPU acceleration Answer: A Explanation: --headless runs the browser in a non-graphical mode, useful for automated pipelines. Question 23. Which of the following statements about driver.getPageSource() is TRUE? A) It returns a promise that resolves to the HTML source of the current page. B) It returns a live DOM object. C) It automatically waits for the page to load. D) It can be used to retrieve JavaScript variables. Answer: A Explanation: getPageSource() provides the raw HTML as a string. Question 24. When using Selenium with JavaScript, how can you handle a new browser window that opens after clicking a link?
A) driver.switchTo().newWindow() B) driver.getAllWindowHandles().then(handles => driver.switchTo().window(handles[1])) C) driver.switchTo().window('new') D) driver.switchTo().windowByTitle('New Window') Answer: B Explanation: Retrieve all window handles, then switch to the second handle (index 1). Question 25. Which of the following is the correct way to define a test case in Jest for a Selenium script? A) test('should login', async () => { /* test steps / }); B) it('should login', () => { / test steps / }); C) describe('Login Test', async () => { / steps / }); D) suite('Login Test', () => { / steps */ }); Answer: A Explanation: Jest uses test or it; when async, you must mark the function as async. Question 26. What does the driver.actions().dragAndDrop(source, target).perform() command accomplish? A) Drags source element to target element using native events B) Simulates a click on source then target C) Moves the mouse cursor to source only D) Scrolls the page to source element Answer: A Explanation: The dragAndDrop action chain performs a drag-and-drop operation. Question 27. Which of the following is the correct way to set a custom HTTP header for all requests using Chrome DevTools Protocol in Selenium? A) driver.executeCdpCommand('Network.setExtraHTTPHeaders', { headers: { 'X- Test': 'value' } })
Answer: B Explanation: You must iterate over driver.getAllWindowHandles(), compare each window’s title, then switch to the matching handle. Question 31. What is the effect of calling driver.quit() at the end of a test suite? A) Only closes the current tab B) Closes the browser and ends the WebDriver session C) Forces a page refresh D) Deletes all cookies but keeps the browser open Answer: B Explanation: quit() terminates the session and closes all associated windows. Question 32. Which of the following is the correct syntax to define a Selenium test using the Cucumber framework in JavaScript? A) Given('I open the site', async function() { await driver.get(url); }); B) When('I click button', function() { driver.click('#btn'); }); C) Then('I verify title', async () => { expect(await driver.getTitle()).toBe('Home'); }); D) Feature('Login Feature') { /* steps */ } Answer: A Explanation: Cucumber step definitions use Given/When/Then with a function; async is needed for WebDriver calls. **Question 33. Which command is used to retrieve the title of the current page? ** A) driver.title() B) driver.getTitle() C) driver.pageTitle() D) driver.getPageTitle() Answer: B Explanation: getTitle() returns a promise that resolves to the page title.
Question 34. In Selenium, what does the StaleElementReferenceException indicate? A) The element is hidden behind another element B) The element no longer exists in the DOM C) The element is not clickable due to overlay D) The element is disabled Answer: B Explanation: The element reference became stale because the DOM changed after it was located. Question 35. Which of the following is the proper way to set a timeout for page load in Selenium WebDriver for JavaScript? A) driver.manage().timeouts().pageLoadTimeout(10000) B) driver.setPageLoadTimeout(10000) C) driver.manage().setTimeouts({ pageLoad: 10000 }) D) driver.timeouts.pageLoad(10000) Answer: C Explanation: setTimeouts accepts an object; pageLoad sets the maximum time to wait for a page to load. Question 36. Which of these options is the correct way to retrieve a list of elements matching a CSS selector .item? A) driver.findElements(By.css('.item')) B) driver.findElements('.item') C) driver.getElements(By.css('.item')) D) driver.getElements('.item') Answer: A Explanation: findElements returns a promise that resolves to an array of matching WebElements. Question 37. How can you verify that a checkbox with ID “agree” is selected?
C) new ChromeDriver(); D) new Builder().setChromeOptions(new chrome.Options()).build(); Answer: C Explanation: There is no ChromeDriver class directly exported; you must use Builder. Question 41. When configuring Selenium Grid, what does the “maxSession” capability control? A) Maximum number of concurrent browsers per node B) Maximum duration of a session in minutes C) Maximum number of Selenium versions supported D) Maximum number of nodes that can register Answer: A Explanation: maxSession defines how many concurrent sessions a node can run. Question 42. Which of the following best describes the purpose of the await driver.sleep(2000); command? A) Implicitly wait for any element up to 2 seconds B) Pause execution for exactly 2 seconds regardless of conditions C) Wait until page load completes within 2 seconds D) Wait for an element with ID “sleep” to appear Answer: B Explanation: sleep is a hard wait; it pauses the test for the specified time. Question 43. In Selenium with JavaScript, which method is used to retrieve the value of the “data-id” attribute from an element? A) element.getAttribute('data-id') B) element.getAttributeValue('data-id') C) element.attribute('data-id') D) element.getProp('data-id') Answer: A
Explanation: getAttribute returns the attribute’s value as a string. Question 44. Which of the following is the correct way to scroll to the bottom of the page using JavaScript execution? A) driver.executeScript('window.scrollTo(0, document.body.scrollHeight)'); B) driver.scrollToBottom(); C) driver.executeScript('window.scrollBottom()'); D) driver.actions().scrollBy(0, 10000).perform(); Answer: A Explanation: The script scrolls to the maximum Y coordinate, reaching the bottom. Question 45. What is the primary advantage of using the Page Factory pattern in Selenium JavaScript? A) It eliminates the need for locators B) It lazily initializes WebElements when they are first used C) It automatically retries failed actions D) It runs tests in parallel by default Answer: B Explanation: Page Factory (via getters) creates elements on demand, improving performance. Question 46. Which of the following commands will close only the current browser tab, leaving the session alive? A) driver.close() B) driver.quit() C) driver.shutdown() D) driver.end() Answer: A Explanation: close() closes the active window; quit() ends the entire session.
B) It provides a fluent API for custom wait conditions. C) It automatically retries failed assertions. D) It sets the default implicit wait. Answer: B Explanation: waitUntil allows you to define custom functions that Selenium will poll until true. Question 51. Which of the following statements about the driver.takeScreenshot() method is FALSE? A) It returns a Base64-encoded string. B) It can be called only after a page is fully loaded. C) It can be saved to a file using fs.writeFile. D) It works in headless mode. Answer: B Explanation: Screenshots can be taken at any moment; the page does not need to be fully loaded. Question 52. In Selenium, what is the effect of calling driver.manage().timeouts().scriptTimeout(30000)? A) Sets the timeout for page loads to 30 seconds. B) Sets the maximum time to wait for asynchronous JavaScript execution. C) Limits the time for implicit waits. D) Controls the time for explicit waits. Answer: B Explanation: scriptTimeout defines how long WebDriver will wait for async scripts (e.g., executeAsyncScript) to finish. Question 53. Which of the following code snippets correctly switches to an alert and dismisses it? A) await driver.switchTo().alert().dismiss(); B) await driver.alert().dismiss(); C) await driver.switchTo().dismissAlert();
D) await driver.handleAlert().dismiss(); Answer: A Explanation: You must switch to the alert, then call dismiss(). Question 54. Which of the following is a recommended way to handle test data that varies per environment (e.g., dev, staging, prod) in Selenium JavaScript projects? A) Hard-code URLs in each test file. B) Use a configuration module that reads from environment variables. C) Store all URLs in a single large JSON file without separation. D) Write separate test suites for each environment. Answer: B Explanation: Environment-specific config files or env variables keep tests flexible and maintainable. Question 55. What does the driver.actions().move({origin: element}).perform() command accomplish? A) Moves the mouse cursor to the center of the given element. B) Drags the element to a new location. C) Scrolls the page until the element is visible. D) Clicks on the element. Answer: A Explanation: move moves the pointer to the element’s location without clicking. Question 56. Which of the following statements about driver.findElement(By.linkText('Home')) is TRUE? A) It locates an anchor element whose visible text exactly matches “Home”. B) It locates any element with the attribute linkText="Home". C) It only works with CSS selectors. D) It is case-insensitive. Answer: A
Question 60. In a Selenium test suite using the Mocha framework, where should you place driver.quit() to ensure the browser closes after all tests have run? A) Inside each test case’s afterEach hook. B) In a global after hook. C) At the beginning of the first test. D) Inside beforeEach. Answer: B Explanation: The after hook runs once after the entire suite, making it ideal for cleanup. Question 61. Which Selenium command would you use to verify that a dropdown with ID “country” contains an option with the value “US”? A) let options = await driver.findElement(By.id('country')).getOptions(); expect(options).toContain('US'); B) let select = new Select(driver.findElement(By.id('country'))); expect(await select.getOptions()).toContainEqual({value: 'US'}); C) await driver.findElement(By.id('country')).selectByValue('US'); D) await driver.findElement(By.id('country')).isOptionPresent('US'); Answer: B Explanation: The Select utility (from selenium-webdriver) allows retrieval of all option elements; you can then assert the presence of the desired value. Question 62. What is the purpose of the driver.wait(until.stalenessOf(element), 5000) command? A) Waits until the element becomes invisible. B) Waits until the element is removed from the DOM. C) Waits until the element is clickable. D) Waits until the element’s text changes. Answer: B Explanation: stalenessOf returns true when the element is no longer attached to the DOM.
Question 63. Which of the following statements about using async/await with Selenium WebDriver promises is FALSE? A) Every WebDriver call returns a promise that can be awaited. B) Using await eliminates the need for .then() chains. C) await can be used only inside functions marked async. D) await automatically retries failed commands. Answer: D Explanation: await does not retry; it simply waits for the promise to settle. Question 64. In Selenium Grid, what does the “browserName” capability specify? A) The operating system of the node. B) The version of Selenium server. C) The type of browser to launch (e.g., chrome, firefox). D) The network bandwidth limit. Answer: C Explanation: browserName tells the hub which browser to start on the node. Question 65. Which of the following is the correct way to perform a right-click (context click) on an element using Selenium actions? A) driver.actions().contextClick(element).perform(); B) driver.actions().rightClick(element).perform(); C) driver.actions().click(element, {button: 2}).perform(); D) driver.actions().mouseDown(element, 2).perform(); Answer: A Explanation: contextClick performs a right-click on the target element. Question 66. What is the main advantage of using the webdriver-manager npm package in a Selenium project? A) It provides a GUI for test execution. B) It automatically downloads and manages browser driver binaries.