A. The method find_element should be find_elements
B. The CSS selector is incorrect because it looks for a button inside an element with id 'login', which might not exist
C. The By.CSS_SELECTOR should be By.CSS
D. The selector should use a class instead of an ID
Solution
Step 1: Understand the CSS selector meaning
The selector "#login button" looks for a button inside an element with id 'login'. If such structure doesn't exist, it fails.
Step 2: Check other options for correctness
find_element is correct for single element; By.CSS_SELECTOR is correct; using class instead of ID is unrelated to the error.
Final Answer:
The CSS selector is incorrect because it looks for a button inside an element with id 'login', which might not exist -> Option B
Quick Check:
Selector must match actual page structure [OK]
Hint: Verify page structure matches your CSS selector path [OK]
Common Mistakes:
Using wrong By constants like By.CSS
Confusing find_element with find_elements
Assuming element hierarchy without checking HTML
5. You want to select all visible buttons with the class 'action' but avoid hidden ones. Which Selenium selector strategy ensures reliability?
hard
A. Use class name selector "action" only
B. Use XPath "//button[contains(@class, 'action') and not(contains(@style, 'display:none'))]"
C. Use tag name selector "button" only
D. Use CSS selector "button.action" and then filter elements by checking visibility in code
Solution
Step 1: Understand selector limitations for visibility
CSS selectors cannot directly filter visible elements; visibility must be checked in code after selection.
Step 2: Evaluate each option's reliability
Use CSS selector "button.action" and then filter elements by checking visibility in code selects all buttons with class 'action' and filters visibility in code, ensuring reliability. Use XPath "//button[contains(@class, 'action') and not(contains(@style, 'display:none'))]" tries to filter by style attribute which may not cover all hidden cases. Options A and D are too broad.
Final Answer:
Use CSS selector "button.action" and then filter elements by checking visibility in code -> Option D
Quick Check:
Filter visibility in code after selecting by stable CSS selector [OK]
Hint: Select by class, then check visibility in code for reliable filtering [OK]
Common Mistakes:
Relying on CSS or XPath to filter visibility only
Using too broad selectors causing false matches
Ignoring dynamic visibility changes in tests
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.