0% found this document useful (0 votes)
31 views11 pages

Scenarios Based Question

The document presents a series of Selenium WebDriver scenarios and questions related to web automation tasks, such as retrieving page titles, maximizing browser windows, handling multiple tabs, and managing checkboxes. Each scenario includes specific coding tasks and multiple-choice questions to assess understanding of Selenium functionalities. The content is structured to guide users through practical applications of Selenium in testing web applications.

Uploaded by

Shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views11 pages

Scenarios Based Question

The document presents a series of Selenium WebDriver scenarios and questions related to web automation tasks, such as retrieving page titles, maximizing browser windows, handling multiple tabs, and managing checkboxes. Each scenario includes specific coding tasks and multiple-choice questions to assess understanding of Selenium functionalities. The content is structured to guide users through practical applications of Selenium in testing web applications.

Uploaded by

Shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

STEP CAMPUS

SCENARIO
BASED
QUESTIONS
SUBSCRIBE
1) Ravi wants to go to website (https://www.facebook.com) and want to get the title of that page and
display that on console. Choose correct option from below.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class DemoClass3 {
public class DemoClass3 {
public static void main(String[] args) {
public static void main(String[] args) { // TODO Auto-generated method stub
// TODO Auto-generated method stub System.setProperty("webdriver.chrome.driver",C:\\Work\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver",C:\\Work\\chromedriver.exe"); WebDriver driver = new ChromeDriver();
WebDriver driver = new ChromeDriver(); driver.fetch("https://www.facebook.com");
driver.get("https://www.facebook.com");
System.out.println("Title of webpage is :" +driver.getTitle());
System.out.println("Title of webpage is :" +driver.getTitle());

import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;


import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeDriver;

public class DemoClass3 { public class DemoClass3 {

public static void main(String[] args) { public static void main(String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",C:\\Work\\chromedriver.exe"); System.setProperty("webdriver.chrome.driver",C:\\Work\\chromedriver.exe");
WebDriver driver = new chromeDriver(); WebDriver driver = new ChromeDriver();
driver.go.to("https://www.facebook.com"); driver.url("https://www.facebook.com");

System.out.println("Title of webpage is :" +driver.getTitle()); System.out.println("Title of webpage is :" +driver.getTitle());


2) While working on the website, Umesh observed that the testing should be done in maximized
mode.
choose the code below to help Umesh for maximizing the window.

public static void main(String[] args) throws InterruptedException public static void main(String[] args) throws InterruptedException
{ {

System.setProperty("webdriver.chrome.driver","./src/resources/c System.setProperty("webdriver.chrome.driver","./src/resources/c
hromedriver"); hromedriver");
WebDriver driver = new chromedriver(); WebDriver driver = new ChromeDriver();
driver.manage().window().maximize(); driver.manage().maximize().window();
driver.get("https://demoqa.com/browser-windows"); driver.get("https://demoqa.com/browser-windows");

public static void main(String[] args) throws InterruptedException


public static void main(String[] args) throws InterruptedException {
{

System.setProperty("webdriver.chrome.driver","./src/resources/c
System.setProperty("webdriver.chrome.driver","./src/resources/chr
hromedriver"); omedriver");
WebDriver driver = new ChromeDriver(); WebDriver driver = new ChromeDriver();
driver.manage().window().maximize(); driver.manage().window().maximize();
driver.fetch("https://demoqa.com/browser-windows"); driver.get("https://demoqa.com/browser-windows");
3) Shivam is a Tester, which working with the website he noticed that there are multiple tabs need
to open for checking all the elments. which command he has to use for handling multiple browsers.

String mainWindowHandle = driver.getWindowHandle();


String mainWindowHandle = driver.getWindowHandle();

Set<String> allWindowHandles = driver.getWindowHandle();


Set<List> allWindowHandles = driver.getWindowHandles();

String mainWindowHandle = driver.getWindowHandle(); String mainWindowHandle = driver.getWindowHandle();

Set<List> allWindowHandles = driver.getWindowHandles();


Set<String> allWindowHandles = driver.getWindowHandles();
4) Scenario: You need to write a Selenium script to select a checkbox that is
initially unchecked.

Question: How would you achieve this in Selenium WebDriver?

A. checkbox.click()

B. checkbox.select()

C. checkbox.setSelected(true)

D. checkbox.check()
5) Scenario: You have a dynamic list of checkboxes generated by JavaScript on a web page, and you need to
wait for these checkboxes to be present before interacting with them in your Selenium test.

Question: Which WebDriver wait condition would you use to achieve this?

A. new WebDriverWait(driver,
10).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='checkbox']")));

B. new WebDriverWait(driver,
10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[type='checkbox']")));

C. new WebDriverWait(driver,
10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("input[type='checkbox']")));

D. new WebDriverWait(driver,
10).until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector("input[type='checkbox']"),
"Checkbox Label"));
6) Scenario: In your automated test, you have a "Select All" checkbox that should
check all other checkboxes when clicked.

Question: How would you verify that all checkboxes are selected after clicking the
"Select All" checkbox using Selenium?

A. Loop through all checkboxes and use checkbox.isSelected() for each one.

B. Check the value of checkbox.getAttribute("checked") for each checkbox.

C. Use checkbox.isEnabled() for each checkbox.

D. Use checkbox.isDisplayed() for each checkbox.


7) Scenario: You need to ensure that a dropdown menu for selecting user roles
(e.g., Admin, Editor, Viewer) is accessible to users with disabilities.

Question: Which of the following practices will improve the accessibility of the
dropdown menu?

A. Using a <div> element styled to look like a dropdown instead of a <select>


element.

B. Adding role="dropdown" to the <select> element.

C. Using a <label> element with the for attribute to associate it with the <select>
element.

D. Avoiding the use of JavaScript to manipulate the dropdown.


8) Scenario: Your test needs to verify that the current URL contains a specific
query parameter after performing a search action.

Question: How would you verify this using Selenium?

A. assert driver.getCurrentUrl().contains("?search=query");

B. assert driver.getCurrentUrl().matches("?search=query");

C. assert driver.getCurrentUrl().includes("?search=query");

D. assert driver.getCurrentUrl().endsWith("?search=query");
9) Scenario: You need to automate a test where you click a button that opens a new tab. After clicking,
you need to switch to the new tab.

Question: Which sequence of Selenium WebDriver commands would you use to handle this scenario?

A. driver.findElement(By.id("button")).click(); driver.switchTo().window("new tab");

B. driver.findElement(By.id("button")).click(); Set<String> handles = driver.getWindowHandles();


driver.switchTo().window(handles.toArray()[1].toString());

C. driver.findElement(By.id("button")).click(); driver.switchTo().alert().accept();

D. driver.findElement(By.id("button")).click(); driver.navigate().to("new tab URL");


10) Scenario: Your test script should wait until the URL of the page contains the path
"/profile" after navigating to a user profile page.

Question: Which WebDriver wait condition would you use?

A. new WebDriverWait(driver,
10).until(ExpectedConditions.urlToBe("http://example.com/profile"));

B. new WebDriverWait(driver, 10).until(ExpectedConditions.urlContains("/profile"));

C. new WebDriverWait(driver, 10).until(ExpectedConditions.titleContains("/profile"));

D. new WebDriverWait(driver,
10).until(ExpectedConditions.visibilityOfElementLocated(By.url("/profile")));

You might also like