Hint: Use [attr='value'] to select by attribute [OK]
Common Mistakes:
Missing quotes around attribute value
Using # for attribute instead of []
Incorrect syntax like input.class='input-field'
4. Identify the error in this CSS selector used in Selenium: driver.findElement(By.cssSelector("div#main .content > p:first-child")); What is wrong with this selector?
medium
A. The pseudo-class ':first-child' is not supported in CSS selectors.
B. The space between 'div#main' and '.content' is incorrect.
C. The '>' combinator cannot be used with classes.
D. The selector syntax is correct and will work as expected.
Solution
Step 1: Analyze the selector components
The selector targets a p element that is the first child inside an element with class content, which is inside a div with id main.
Step 2: Check CSS selector validity in Selenium
All parts including #main, .content, child combinator >, and pseudo-class :first-child are valid CSS selectors supported by Selenium.
Final Answer:
The selector syntax is correct and will work as expected. -> Option D
Quick Check:
Valid CSS selector syntax = correct [OK]
Hint: Check if selector uses valid CSS syntax supported by Selenium [OK]
Common Mistakes:
Assuming pseudo-classes like :first-child are unsupported
Misunderstanding combinator usage
Thinking spaces between selectors are always wrong
5. You want to select all button elements that have both the class btn and an attribute data-action equal to save. Which CSS selector is correct?
hard
A. button#btn[data-action=save]
B. button.btn[data-action='save']
C. button .btn[data-action='save']
D. button.btn[data-action=save]
Solution
Step 1: Combine class and attribute selectors correctly
To select elements with a class and attribute, chain selectors without spaces: button.btn[data-action='save'].
Step 2: Verify syntax details
Quotes around attribute value are recommended for exact matching; no spaces between element, class, and attribute selectors.
Final Answer:
button.btn[data-action='save'] -> Option B
Quick Check:
Combine selectors without spaces = button.btn[data-action='save'] [OK]
Hint: Chain selectors without spaces; quote attribute values [OK]
Common Mistakes:
Using spaces between element and class selectors
Omitting quotes around attribute values
Using # instead of . for class
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.