Scenarios Based Question
Scenarios Based Question
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());
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");
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");
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.
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.
Question: Which of the following practices will improve the accessibility of the
dropdown menu?
C. Using a <label> element with the for attribute to associate it with the <select>
element.
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?
C. driver.findElement(By.id("button")).click(); driver.switchTo().alert().accept();
A. new WebDriverWait(driver,
10).until(ExpectedConditions.urlToBe("http://example.com/profile"));
D. new WebDriverWait(driver,
10).until(ExpectedConditions.visibilityOfElementLocated(By.url("/profile")));