MCQs on Textbox Handling Using Selenium Java
Which Selenium WebDriver method is used to enter text into a textbox?
a) typeText()
b) enterText()
c) sendKeys()
d) setText()
Answer: c) sendKeys()
How can you clear the text from a textbox in Selenium WebDriver?
a) clearText()
b) reset()
c) deleteText()
d) clear()
Answer: d) clear()
What is the correct syntax to locate a textbox by its name attribute and enter text "Hello"?
a) driver.findElement(By.id("textbox")).sendKeys("Hello");
b) driver.findElement(By.name("textbox")).sendKeys("Hello");
c) driver.findElement(By.className("textbox")).sendKeys("Hello");
d) driver.findElement(By.tagName("textbox")).sendKeys("Hello");
Answer: b) driver.findElement(By.name("textbox")).sendKeys("Hello");
If you want to verify whether a textbox is enabled or not, which method would you use?
a) isVisible()
b) isSelected()
c) isEnabled()
d) isDisplayed()
Answer: c) isEnabled()
Which method is used to retrieve the current text entered in a textbox?
a) getText()
b) getAttribute("value")
c) getValue()
d) getContent()
Answer: b) getAttribute("value")
To find a textbox using its ID and enter text "Automation", what is the correct line of code?
a) driver.findElement(By.xpath("textbox")).sendKeys("Automation");
b) driver.findElement(By.id("textbox")).sendKeys("Automation");
c) driver.findElement(By.name("textbox")).sendKeys("Automation");
d) driver.findElement(By.linkText("textbox")).sendKeys("Automation");
Answer: b) driver.findElement(By.id("textbox")).sendKeys("Automation");
How do you simulate pressing the ENTER key in a textbox using Selenium WebDriver?
a) element.sendKeys(Keys.RETURN)
b) element.sendKeys(Keys.ENTER)
c) element.press(Keys.ENTER)
d) Both a and b
Answer: d) Both a and b
What is the return type of the getAttribute() method when used to get the value of a textbox?
a) int
b) String
c) boolean
d) void
Answer: b) String
Which exception might you encounter if you try to interact with a non-existent textbox element?
a) NoSuchElementException
b) ElementNotVisibleException
c) StaleElementReferenceException
d) InvalidElementStateException
Answer: a) NoSuchElementException
To clear text from a textbox identified by CSS selector, what is the correct Selenium WebDriver command?
a) driver.findElement(By.cssSelector("textbox")).reset();
b) driver.findElement(By.cssSelector("textbox")).delete();
c) driver.findElement(By.cssSelector("textbox")).clear();
d) driver.findElement(By.cssSelector("textbox")).removeText();
Answer: c) driver.findElement(By.cssSelector("textbox")).clear();
How would you verify if a textbox is present on the webpage?
a) isPresent()
b) isDisplayed()
c) isVisible()
d) isEnabled()
Answer: b) isDisplayed()
Which method would you use to input a large amount of text into a textbox without typing each character individually?
a) setValue()
b) sendKeys(CharSequence...)
c) enterText()
d) appendText()
Answer: b) sendKeys(CharSequence...)
If you want to append text to the existing text in a textbox, which of the following commands should you use?
a) element.clear(); element.sendKeys("new text");
b) element.sendKeys(Keys.END, "new text");
c) element.clear(); element.sendKeys("new text appended");
d) element.sendKeys("new text appended");
Answer: b) element.sendKeys(Keys.END, "new text");
Which of the following methods allows you to verify if a textbox contains the expected default text?
a) getText()
b) getAttribute("value")
c) getCssValue("content")
d) isEnabled()
Answer: b) getAttribute("value")
What is the Selenium method to handle textboxes that require clearing old values before entering new ones?
a) sendKeys()
b) clear(), then sendKeys()
c) reset()
d) deleteText(), then sendKeys()
Answer: b) clear(), then sendKeys()
No comments:
Post a Comment