What does the isDisplayed() method check in Selenium?
It checks if a web element is visible on the page to the user. If the element is hidden or not present, it returns false.
Click to reveal answer
beginner
What is the purpose of the isEnabled() method in Selenium?
It checks if a web element is enabled and can be interacted with, like a button that is clickable or a text box that can be typed into.
Click to reveal answer
beginner
How does isSelected() help in testing?
It checks if an element like a checkbox, radio button, or option in a dropdown is currently selected or checked.
Click to reveal answer
beginner
Example: What will checkbox.isSelected() return if the checkbox is checked?
It will return true because the checkbox is selected.
Click to reveal answer
intermediate
Why is it important to check element state before interacting in Selenium tests?
Because trying to click or type on invisible, disabled, or unselected elements can cause test failures or errors. Checking state helps write stable tests.
Click to reveal answer
Which Selenium method checks if an element is visible on the page?
AisDisplayed()
BisEnabled()
CisSelected()
DisVisible()
✗ Incorrect
isDisplayed() returns true if the element is visible to the user.
What does isEnabled() return if a button is grayed out and cannot be clicked?
Afalse
Btrue
Cnull
Dthrows exception
✗ Incorrect
isEnabled() returns false if the element is disabled and cannot be interacted with.
Which element state method would you use to check if a checkbox is checked?
AisDisplayed()
BisSelected()
CisChecked()
DisEnabled()
✗ Incorrect
isSelected() checks if checkboxes or radio buttons are selected.
If element.isDisplayed() returns false, what does it mean?
AElement is enabled
BElement is visible
CElement is hidden or not present
DElement is selected
✗ Incorrect
isDisplayed() returning false means the element is not visible on the page.
Why should you check isEnabled() before clicking a button?
ATo confirm the button is visible
BTo confirm the button is selected
CTo confirm the button is hidden
DTo confirm the button is clickable
✗ Incorrect
Checking isEnabled() ensures the button can be clicked without errors.
Explain the difference between isDisplayed(), isEnabled(), and isSelected() in Selenium.
Think about what each method tells you about the element's state.
You got /3 concepts.
Describe a scenario where checking element state methods prevents test failures.
Consider what happens if you interact with elements not ready for action.
You got /3 concepts.
Practice
(1/5)
1. Which Selenium WebDriver method would you use to check if a button is visible on the web page?
easy
A. getText()
B. isEnabled()
C. isSelected()
D. isDisplayed()
Solution
Step 1: Understand the purpose of isDisplayed()
This method checks if an element is visible on the page, meaning it is rendered and not hidden.
Step 2: Compare with other methods
isEnabled() checks if the element can be interacted with, isSelected() checks selection state, and getText() returns text content, so they don't check visibility.
Final Answer:
isDisplayed() -> Option D
Quick Check:
Visibility check = isDisplayed() [OK]
Hint: Visibility means use isDisplayed() method [OK]
Common Mistakes:
Confusing isDisplayed() with isEnabled()
Using isSelected() for visibility
Thinking getText() checks visibility
2. Which of the following is the correct syntax to check if a checkbox element is selected in Selenium Java?
easy
A. checkbox.isSelected();
B. checkbox.isDisplayed();
C. checkbox.isEnabled();
D. checkbox.getSelected();
Solution
Step 1: Recall the method to check selection state
The correct method to check if a checkbox or radio button is selected is isSelected().
Step 2: Verify syntax correctness
checkbox.isSelected(); is valid Java syntax. getSelected() does not exist, and the others check different states.
Final Answer:
checkbox.isSelected(); -> Option A
Quick Check:
Check selection = isSelected() [OK]
Hint: Use isSelected() to check checkbox state [OK]
Common Mistakes:
Using getSelected() which is invalid
Confusing isDisplayed() with isSelected()
Using isEnabled() to check selection
3. Given the following code snippet, what will be the output if the button is visible but disabled?
Step 1: Understand the purpose of isEnabled() vs isSelected()
isEnabled() checks if the element can be interacted with, not if it is selected.
Step 2: Identify correct method to check selection
To check if a radio button is selected, isSelected() must be used.
Final Answer:
Should use isSelected() instead of isEnabled() -> Option A
Quick Check:
Selection check = isSelected() [OK]
Hint: Use isSelected() to check radio button selection [OK]
Common Mistakes:
Using isEnabled() to check selection
Assuming enabled means selected
Ignoring method purpose differences
5. You want to write a test that clicks a checkbox only if it is visible, enabled, and not already selected. Which of the following code snippets correctly implements this logic?
hard
A. if(!checkbox.isDisplayed() && checkbox.isEnabled() && checkbox.isSelected()) {
checkbox.click();
}
B. if(checkbox.isDisplayed() || checkbox.isEnabled() || checkbox.isSelected()) {
checkbox.click();
}
C. if(checkbox.isDisplayed() && checkbox.isEnabled() && !checkbox.isSelected()) {
checkbox.click();
}
D. if(checkbox.isDisplayed() && !checkbox.isEnabled() && !checkbox.isSelected()) {
checkbox.click();
}
Solution
Step 1: Understand the required conditions
The checkbox must be visible (isDisplayed()), enabled (isEnabled()), and not selected (!isSelected()).
Step 2: Analyze each option
if(checkbox.isDisplayed() && checkbox.isEnabled() && !checkbox.isSelected()) {
checkbox.click();
} uses AND (&&) to combine all correct conditions and negates isSelected() to ensure it is not selected before clicking.