Friday, August 23, 2024

Password Handling Using Selenium Java MCQ

MCQs on Password Handling Using Selenium Java

Which WebElement method is used to enter a password into a password field using Selenium WebDriver?

a) sendKeys()

b) setText()

c) typePassword()

d) inputPassword()


Answer: a) sendKeys()


What is the best way to locate a password input field using its name attribute in Selenium WebDriver?

a) driver.findElement(By.id("password")).sendKeys("password123");

b) driver.findElement(By.name("password")).sendKeys("password123");

c) driver.findElement(By.className("password")).sendKeys("password123");

d) driver.findElement(By.tagName("password")).sendKeys("password123");


Answer: b) driver.findElement(By.name("password")).sendKeys("password123");


Which Selenium WebDriver method is used to clear the contents of a password field?

a) delete()

b) removeText()

c) clear()

d) reset()


Answer: c) clear()


How can you verify if a password field is enabled for user interaction?

a) isVisible()

b) isEnabled()

c) isDisplayed()

d) isAccessible()


Answer: b) isEnabled()


Which attribute would you check to ensure that an input field is of type password?

a) getAttribute("text")

b) getAttribute("type")

c) getAttribute("password")

d) getAttribute("fieldType")


Answer: b) getAttribute("type")


If you want to find a password field by its ID and enter text "SecurePass", what is the correct line of code?

a) driver.findElement(By.xpath("password")).sendKeys("SecurePass");

b) driver.findElement(By.id("password")).sendKeys("SecurePass");

c) driver.findElement(By.name("password")).sendKeys("SecurePass");

d) driver.findElement(By.linkText("password")).sendKeys("SecurePass");


Answer: b) driver.findElement(By.id("password")).sendKeys("SecurePass");


What will getAttribute("value") return when called on a password field?

a) The masked password (e.g., "*******")

b) The actual password

c) Null

d) The placeholder text


Answer: b) The actual password


To ensure a password field is present on the page before interacting with it, which method would you use?

a) isEnabled()

b) isSelected()

c) isDisplayed()

d) isPresent()


Answer: c) isDisplayed()


Which exception is thrown if the password field element is not found on the page?

a) ElementNotVisibleException

b) NoSuchElementException

c) ElementNotSelectableException

d) TimeoutException


Answer: b) NoSuchElementException


How would you simulate typing a password in a field followed by pressing the ENTER key?

a) element.sendKeys("password123", Keys.RETURN);

b) element.sendKeys("password123" + Keys.RETURN);

c) element.sendKeys("password123", Keys.ENTER);

d) Both a and c


Answer: d) Both a and c


Which Selenium method would you use to hide or mask input text for a password field?

a) setType("password")

b) sendKeys(Keys.HIDE)

c) This feature is automatically handled by the browser

d) maskText()

Answer: c) This feature is automatically handled by the browser



Which locator strategy would you use to find a password input field when the type attribute is set as "password"?

a) By.tagName("password")

b) By.cssSelector("input[type='password']")

c) By.id("password")

d) By.linkText("password")

Answer: b) By.cssSelector("input[type='password']")


What will happen if you try to retrieve the value of a masked password using getText()?

a) It will return the actual password

b) It will return an empty string

c) It will return the masked version (e.g., "*******")

d) It will throw an exception

Answer: b) It will return an empty string (Recheck this answer)


To verify that a password field's value is hidden (masked), you should check:

a) element.isMasked()

b) element.getAttribute("type").equals("password")

c) element.getText().equals("*******")

d) element.getValue().equals("password")

Answer: b) element.getAttribute("type").equals("password")



Which command sequence will clear and then enter a new password in a password field?

a) element.clear(); element.sendKeys("newPass123");

b) element.sendKeys(Keys.DELETE, "newPass123");

c) element.reset(); element.sendKeys("newPass123");

d) element.deleteText(); element.sendKeys("newPass123");

Answer: a) element.clear(); element.sendKeys("newPass123");


No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...