Recall & Review
beginner
What is a CSS pseudo-class?
A CSS pseudo-class is a keyword added to selectors that specifies a special state of the selected elements, like :hover for when a mouse is over an element.Click to reveal answer
beginner
How can you select the first child of a parent element using CSS pseudo-classes?
Use the :first-child pseudo-class to select the first child element of its parent.Click to reveal answer
intermediate
In Selenium with Python, how do you use a CSS pseudo-class in a locator?You can use driver.find_element(By.CSS_SELECTOR, 'tag:pseudo-class') to locate elements matching the pseudo-class, for example, 'li:first-child'.
Click to reveal answer
intermediate
What does the :nth-child(n) pseudo-class do?It selects the nth child element of its parent, where n can be a number, keyword, or formula.
Click to reveal answer
intermediate
Why should you prefer CSS pseudo-classes over XPath in Selenium for some selections?
CSS selectors with pseudo-classes are often faster and simpler for selecting elements based on position or state, improving test speed and readability.
Click to reveal answer
Which CSS pseudo-class selects an element when the mouse pointer is over it?
✗ Incorrect
The :hover pseudo-class applies when the mouse pointer is over an element.
How would you select the third child of a list using CSS pseudo-classes?
✗ Incorrect
:nth-child(3) selects the third child element.
In Selenium Python, which method is used to locate elements by CSS selector?
✗ Incorrect
Use By.CSS_SELECTOR to locate elements with CSS selectors.
Which pseudo-class selects an element that is the only child of its parent?
✗ Incorrect
:only-child selects an element that is the only child of its parent.
Why might CSS pseudo-classes be preferred over XPath in Selenium tests?
✗ Incorrect
CSS selectors with pseudo-classes are often faster and simpler for selecting elements by position or state.
Explain how CSS pseudo-classes can help select elements in Selenium tests.
Think about how you pick elements based on their state or position.
You got /4 concepts.
Describe the difference between :first-child and :nth-child(n) pseudo-classes.
Consider how you pick the first item versus any specific item.
You got /4 concepts.