Last Updated On
Welcome to the Advance Selenium Quiz! This blog post features 25 multiple-choice questions that explore advance concepts of Selenium.
1. Selenium can be used to automate Mobile application?
Select the best answer
a) Yes
b) No
Answer 1
b) No
Selenium itself cannot be directly used to automate mobile applications. However, Selenium can be integrated with tools like Appium, which is specifically designed for automating mobile applications.
2. Selenium can be used to automate Desktop application?
Choose one option
a) Yes
b) No
Answer 2
b) No
3. Does Selenium can be used to automate Captcha or OTP?
Choose one option
a) Yes
b) No
Answer 3
b) No
4. Selenium can handle the Browser cookies?
Choose one option
a) Yes
b) No
Answer 4
a) Yes
5. Can we run Selenium tests in GitHub pipeline?
Choose one option
a) Yes
b) No
Answer 5
a) Yes
6. Selenium tests can be run in GitLab pipeline?
a) Yes
b) No
Answer 6
a) Yes
7. What are the benefits of using Docker in a CI/CD pipeline for Selenium tests?
a) Docker ensures that the same environment is used across development, testing, and production, minimizing environment-related issues.
b) Docker allows you to spin up multiple containers in parallel, thereby speeding up the test execution process.
c) Docker integrates well with CI/CD tools like Jenkins, GitLab CI, CircleCI, and Travis CI, making it easy to run Selenium tests within these systems.
d) All of the above
Answer 7
d) All of the above
8. What does the following Selenium WebDriver code do?
WebDriver driver = new ChromeDriver();
driver.get("https://www.example.com");
WebElement element = driver.findElement(By.id("submitButton"));
element.click();
Choose one option
a) Opens Firefox, navigates to https://www.example.com, finds the element with the id “submitButton”, and clicks it.
b) Opens Chrome, navigates to https://www.example.com, finds the element with the id “submitButton”, and clicks it.
c) Opens Safari, navigates to https://www.example.com, finds the element with the id “submitButton”, and clicks it.
d) Opens Chrome, navigates to https://www.example.com, finds the element with the name “submitButton”, and clicks it.
Answer 8
b) Opens Chrome, navigates to “https://www.example.com”, finds the element with the id “submitButton”, and clicks it.
9. What will the following code snippet do?
WebDriver driver = new ChromeDriver();
driver.get("https://www.example.com");
List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println("Number of links: " + links.size());
Choose one option
a) Prints the text of all the links on the webpage.
b) Prints the total number of links on the webpage.
c) Clicks on all the links on the webpage.
d) Generates an error as `findElements` is not a valid method.
Answer 9
b) Prints the total number of links on the webpage.
10. What exception will be thrown by the following code if the specified element is not found within 10 seconds?
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
Choose one option
a) NoSuchElementException
b) ElementNotVisibleException
c) TimeoutException
d) StaleElementReferenceException
Answer 10
c) TimeoutException
11. Which method is used to handle a JavaScript alert in Selenium WebDriver?
driver.switchTo().___.accept();
Choose one option
a) alert
b) popup
c) window
d) frame
Answer 11
a) alert
12. Which of the following will correctly initialize and use the `Select` class to select an option from a dropdown?
WebElement dropdown = driver.findElement(By.id("dropdown"));
Select select = new Select(dropdown);
select.___("Option 1");
Choose one option
a) click
b) setText
c) selectByVisibleText
d) selectByIndex
Answer 12
c) selectByVisibleText
13. Given the following piece of code, which mouse action is being performed?
Actions actions = new Actions(driver);
WebElement element = driver.findElement(By.id("elementId"));
actions.contextClick(element).perform();
Choose one option
a) Double-click on the element
b) Right-click on the element
c) Drag and drop the element
d) Hover over the element
Answer 13
b) Right-click on the element
14. What is the purpose of the following code snippet?
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("path/to/screenshot.png"));
Choose one option
a) Takes a screenshot and saves it to the specified location.
b) Records a video of the browser session.
c) Prints the HTML source of the current page.
d) Extracts text from an image on the webpage.
Answer 14
a) Takes a screenshot and saves it to the specified location.
15. Which of the following code snippets will switch to a frame by its name or ID?
driver.switchTo().___("frameNameOrId");
Choose one option
a) window
b) alert
c) frame
d) defaultContent
Answer 15
c) frame
16. Given the following Selenium WebDriver code, what does `.sendKeys(Keys.TAB)` achieve?
WebElement inputField = driver.findElement(By.id("inputField"));
inputField.sendKeys("test data");
inputField.sendKeys(Keys.TAB);
Choose one option
a) Submits the form containing the input field.
b) Clears the text in the input field.
c) Moves the focus to the next element in the form.
d) Opens a new browser tab.
Answer 16
c) Moves the focus to the next element in the form.
17. What will the following Java code do?
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Choose one option
a) Waits for 20 seconds before executing any WebDriver command.
b) Sets the timeout for finding elements to 20 seconds.
c) Sets the page load timeout to 20 seconds.
d) Sets the script timeout to 20 seconds.
Answer 17
b) Sets the timeout for finding elements to 20 seconds.
18. What does the following Selenium WebDriver code do?
WebElement table = driver.findElement(By.id("tableId"));
List<WebElement> rows = table.findElements(By.tagName("tr"));
WebElement firstCell = rows.get(0).findElements(By.tagName("td")).get(0);
System.out.println(firstCell.getText());
Choose one option
a) Prints the number of rows in the table with id “tableId”
b) Clicks on the first cell in the table
c) Prints the text from the first cell in the first row of the table with id “tableId”
d) Prints the number of columns in the first row of the table
Answer 18
c) Prints the text from the first cell in the first row of the table with id “tableId”
19. Which of the following code snippets deletes all cookies in the current browser session?
driver.manage().___();
a) removeAllCookies()
b) deleteAllCookies()
c) clearCookies()
d) dropAllCookies()
Answer 19
b) deleteAllCookies()
20. How can you add a new cookie to the browser session in Selenium WebDriver?
Cookie cookie = new Cookie("name", "value");
driver.manage().___(cookie);
Choose one option
a) insertCookie
b) addCookie
c) setCookie
d) putCookie
Answer 20
b) addCookie
21. Which method retrieves all the options from a dropdown as a list of WebElement?
Select dropdown = new Select(driver.findElement(By.id("dropdownId")));
List<WebElement> options = dropdown.___();
a) getAllOptions
b) retrieveOptions
c) findOptions
d) getOptions
Answer 21
d) getOptions
22. What exception is thrown when a Selenium WebDriver command takes too long to execute, exceeding the configured timeout limits?
a) TimeoutException
b) NoSuchElementException
c) WebDriverException
d) ElementNotVisibleException
Answer 22
a) TimeoutException
23. Given the following code snippet, which exception handling mechanism is being demonstrated?
try {
WebElement element = driver.findElement(By.id("submit"));
element.click();
} catch (NoSuchElementException e) {
System.out.println("Element not found.");
}
a) Handling ElementNotVisibleException
b) Handling StaleElementReferenceException
c) Handling NoSuchElementException
d) Handling TimeoutException
Answer 23
c) NoSuchElementException
24. Which of the following exceptions is thrown when an action is attempted on an element that is disabled?
a) ElementNotSelectableException
b) InvalidElementStateException
c) ElementNotVisibleException
d) NoSuchElementException
Answer 24
b) InvalidElementStateException
25. What is the appropriate exception to handle when a script attempt to interact with a non-clickable element?
a) ElementNotVisibleException
b) ElementClickInterceptedException
c) StaleElementReferenceException
d) NoSuchElementException
Answer 25
b) ElementClickInterceptedException
We would love to hear from you! Please leave your comments and share your scores in the section below