MCQs on Button Handling Using Selenium Java
Which Selenium WebDriver method is used to click a button?
a) submit()
b) click()
c) navigate()
d) select()
Answer: b) click()
How do you locate a button using its ID in Selenium WebDriver?
a) driver.findElement(By.name("buttonID"))
b) driver.findElement(By.className("buttonID"))
c) driver.findElement(By.id("buttonID"))
d) driver.findElement(By.tagName("buttonID"))
Answer: c) driver.findElement(By.id("buttonID"))
Which of the following methods checks whether a button is displayed on the webpage?
a) isVisible()
b) isDisplayed()
c) isEnabled()
d) isSelected()
Answer: b) isDisplayed()
How can you determine if a button is enabled or disabled using Selenium WebDriver?
a) isEnabled()
b) isVisible()
c) isDisplayed()
d) isClickable()
Answer: a) isEnabled()
Which method is used to retrieve the text of a button in Selenium WebDriver?
a) getText()
b) getAttribute("value")
c) getAttribute("text")
d) getButtonText()
Answer: a) getText()
How do you click a button using its class name in Selenium WebDriver?
a) driver.findElement(By.className("buttonClass")).click();
b) driver.findElement(By.id("buttonClass")).click();
c) driver.findElement(By.name("buttonClass")).click();
d) driver.findElement(By.tagName("buttonClass")).click();
Answer: a) driver.findElement(By.className("buttonClass")).click();
Which of the following Selenium commands will simulate clicking a button using its XPath?
a) driver.findElement(By.name("//button[text()='Submit']")).click();
b) driver.findElement(By.xpath("//button[text()='Submit']")).click();
c) driver.findElement(By.cssSelector("//button[text()='Submit']")).click();
d) driver.findElement(By.linkText("//button[text()='Submit']")).click();
Answer: b) driver.findElement(By.xpath("//button[text()='Submit']")).click();
What will happen if you attempt to click a disabled button using Selenium WebDriver?
a) It will click the button without any issue.
b) It will throw an ElementNotInteractableException.
c) It will throw a NoSuchElementException.
d) It will submit the form.
Answer: b) It will throw an ElementNotInteractableException.
To retrieve the value of a button's attribute, which method would you use?
a) getText("attributeName")
b) getValue("attributeName")
c) getAttribute("attributeName")
d) getProperty("attributeName")
Answer: c) getAttribute("attributeName")
Which of the following methods is used to click a button with a specific tag name?
a) driver.findElement(By.tagName("button")).click();
b) driver.findElement(By.name("button")).click();
c) driver.findElement(By.className("button")).click();
d) driver.findElement(By.linkText("button")).click();
Answer: a) driver.findElement(By.tagName("button")).click();
What will getCssValue("background-color") return when called on a button element?
a) The text of the button
b) The value of the "background-color" CSS property
c) The HTML of the button
d) The ID of the button
Answer: b) The value of the "background-color" CSS property
Which of the following statements correctly retrieves the tooltip of a button?
a) button.getTooltip();
b) button.getAttribute("tooltip");
c) button.getAttribute("title");
d) button.getTooltipText();
Answer: c) button.getAttribute("title");
What is the purpose of the submit() method when used with a button element in Selenium?
a) To click the button
b) To simulate pressing the ENTER key
c) To submit the form containing the button
d) To clear the button's text
Answer: c) To submit the form containing the button
How would you find all buttons with the class name "btn-primary"?
a) driver.findElements(By.className("btn-primary"))
b) driver.findElements(By.id("btn-primary"))
c) driver.findElements(By.tagName("button-primary"))
d) driver.findElements(By.name("btn-primary"))
Answer: a) driver.findElements(By.className("btn-primary"))
To click a button with a dynamic ID that changes every time the page is loaded, which locator strategy is most reliable?
a) By.id()
b) By.name()
c) By.xpath()
d) By.cssSelector()
Answer: c) By.xpath()
No comments:
Post a Comment