MCQs on Introduction to WebDriver | Selenium

Gain insights into Selenium WebDriver architecture, how to write your first Selenium script, and master essential browser commands like open, close, navigate, and maximize to enhance test automation.


MCQs on Introduction to WebDriver

1. WebDriver Architecture

  1. What is the primary role of Selenium WebDriver in test automation?
    a) To manage test data
    b) To execute browser commands programmatically
    c) To analyze test results
    d) To generate test scripts
  2. Which layer in WebDriver architecture directly interacts with the browser?
    a) Test script layer
    b) JSON wire protocol layer
    c) Browser driver
    d) Application under test
  3. What communication protocol is used by Selenium WebDriver for interaction?
    a) HTTP
    b) WebSocket
    c) JSON Wire Protocol
    d) SOAP
  4. Which component of WebDriver acts as a bridge between the test script and the browser?
    a) Selenium Grid
    b) Browser driver
    c) WebDriver API
    d) TestNG
  5. What is the purpose of the WebDriver client library?
    a) To connect multiple browsers simultaneously
    b) To send commands to browser drivers
    c) To log test results
    d) To design user interfaces
  6. What is the correct order of interaction in the WebDriver architecture?
    a) Test script → WebDriver API → Browser → Browser Driver
    b) Test script → WebDriver API → Browser Driver → Browser
    c) Test script → Browser Driver → Browser → WebDriver API
    d) Test script → Browser → Browser Driver → WebDriver API
  7. What does the WebDriver API provide?
    a) A GUI interface for testing
    b) Methods to interact with web elements
    c) Parallel execution of test scripts
    d) A reporting framework
  8. Which browser driver is used to automate tests in Google Chrome?
    a) ChromeDriver
    b) GeckoDriver
    c) EdgeDriver
    d) OperaDriver
  9. How does WebDriver execute commands in the browser?
    a) By directly embedding JavaScript in the browser
    b) By sending JSON commands through the browser driver
    c) By using WebAssembly scripts
    d) By manually triggering browser events
  10. What is one key advantage of Selenium WebDriver over Selenium RC?
    a) It supports JavaScript injection
    b) It interacts directly with browsers
    c) It has in-built reporting capabilities
    d) It requires less coding

2. First Selenium Script

  1. What is the first step to automate a browser using Selenium?
    a) Write test cases
    b) Download and configure the appropriate browser driver
    c) Import libraries for reporting
    d) Create a framework
  2. Which method in WebDriver is used to launch a URL in the browser?
    a) navigateTo()
    b) openURL()
    c) get()
    d) launchURL()
  3. What is the purpose of the System.setProperty method in a Selenium script?
    a) To configure environment variables
    b) To set the path to the browser driver
    c) To define the base URL for tests
    d) To enable reporting
  4. How do you create an instance of Chrome WebDriver?
    a) WebDriver driver = new WebDriver();
    b) WebDriver driver = new ChromeDriver();
    c) Driver driver = new WebDriver();
    d) Driver driver = new ChromeWebDriver();
  5. Which annotation in JUnit is used to write setup code before executing a test?
    a) @Test
    b) @Before
    c) @After
    d) @Initialize
  6. In a Selenium script, how do you close the current browser window?
    a) driver.terminate()
    b) driver.close()
    c) driver.quit()
    d) driver.exit()
  7. What is the difference between driver.close() and driver.quit()?
    a) close() stops the WebDriver, and quit() closes all browser windows
    b) close() closes the current window, while quit() closes all sessions
    c) Both commands perform the same action
    d) close() logs the results, while quit() doesn’t
  8. What is the output of this script:javaCopy codedriver.get("https://example.com"); driver.getTitle(); a) The browser closes
    b) The browser navigates to the URL and fetches the title
    c) An error occurs due to missing return statement
    d) The browser opens, but no URL is loaded
  9. How do you maximize a browser window in Selenium?
    a) driver.maximizeWindow();
    b) driver.window().maximize();
    c) driver.manage().window().maximize();
    d) window.maximize();
  10. Which method pauses a Selenium script for a specified duration?
    a) driver.pause()
    b) Thread.sleep()
    c) driver.delay()
    d) script.hold()

3. Basic Browser Commands

  1. Which command is used to navigate back to the previous page in Selenium?
    a) driver.navigate().back();
    b) driver.goBack();
    c) driver.previous();
    d) navigate.back();
  2. What does driver.getCurrentUrl() return?
    a) The base URL of the website
    b) The complete URL of the currently loaded page
    c) The domain name of the website
    d) The page title
  3. How do you refresh the current page in Selenium?
    a) driver.refresh();
    b) driver.navigate().refresh();
    c) driver.pageRefresh();
    d) driver.reload();
  4. Which command is used to open a new tab in Selenium WebDriver?
    a) driver.newTab();
    b) driver.executeScript("window.open()");
    c) driver.createNewTab();
    d) driver.addTab();
  5. What does driver.manage().timeouts().implicitlyWait() do?
    a) Sets the timeout for loading a URL
    b) Configures the time to wait for all elements to load
    c) Specifies the timeout for closing the browser
    d) Stops the script after the timeout
  6. Which method in WebDriver closes all browser windows and ends the session?
    a) driver.close()
    b) driver.quit()
    c) driver.terminate()
    d) driver.stop()
  7. Which of the following is a valid way to navigate forward in Selenium?
    a) driver.goForward();
    b) driver.navigate().forward();
    c) driver.pageForward();
    d) driver.forward();
  8. Which command opens the browser console in Selenium?
    a) driver.console()
    b) driver.showConsole();
    c) driver.manage().console();
    d) Selenium WebDriver doesn’t support this directly
  9. How do you get the page source of a loaded webpage?
    a) driver.getPageSource();
    b) driver.loadPageSource();
    c) driver.pageSource();
    d) driver.fetchSource();
  10. What is the correct way to navigate to a new URL without restarting the browser?
    a) driver.reload("https://example.com");
    b) driver.navigate().to("https://example.com");
    c) driver.goto("https://example.com");
    d) driver.open("https://example.com");

Answers

QnoAnswer
1b) To execute browser commands programmatically
2c) Browser driver
3c) JSON Wire Protocol
4b) Browser driver
5b) To send commands to browser drivers
6b) Test script → WebDriver API → Browser Driver → Browser
7b) Methods to interact with web elements
8a) ChromeDriver
9b) By sending JSON commands through the browser driver
10b) It interacts directly with browsers
11b) Download and configure the appropriate browser driver
12c) get()
13b) To set the path to the browser driver
14b) WebDriver driver = new ChromeDriver();
15b) @Before
16b) driver.close()
17b) close() closes the current window, while quit() closes all sessions
18b) The browser navigates to the URL and fetches the title
19c) driver.manage().window().maximize();
20b) Thread.sleep()
21a) driver.navigate().back();
22b) The complete URL of the currently loaded page
23b) driver.navigate().refresh();
24b) driver.executeScript("window.open()");
25b) Configures the time to wait for all elements to load
26b) driver.quit()
27b) driver.navigate().forward();
28d) Selenium WebDriver doesn’t support this directly
29a) driver.getPageSource();
30b) driver.navigate().to("https://example.com");

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top