0
0
Selenium Javatesting~5 mins

CSS attribute and pseudo-class selectors in Selenium Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a CSS attribute selector?
A CSS attribute selector matches elements based on the presence or value of an attribute. For example, [type='text'] selects all elements with type attribute equal to 'text'.
Click to reveal answer
intermediate
How do you select elements with a class that starts with 'btn-' using CSS attribute selectors?
Use the selector <code>[class^='btn-']</code>. The <code>^=</code> means 'starts with'. This selects elements whose class attribute value starts with 'btn-'.
Click to reveal answer
beginner
What is a CSS pseudo-class selector?
A CSS pseudo-class selector matches elements in a specific state or position, like <code>:hover</code> for when the mouse is over an element, or <code>:first-child</code> for the first child element.
Click to reveal answer
intermediate
Give an example of using a CSS pseudo-class selector in Selenium Java.
Example: driver.findElement(By.cssSelector("input[type='checkbox']:checked")) selects a checkbox input that is currently checked.
Click to reveal answer
beginner
Why are CSS attribute and pseudo-class selectors useful in Selenium tests?
They allow precise targeting of elements based on attributes or states without relying on IDs or classes alone. This helps make tests more robust and maintainable.
Click to reveal answer
Which CSS selector matches all input elements with a name attribute containing 'user'?
Ainput[name='user']
Binput[name^='user']
Cinput[name$='user']
Dinput[name*='user']
What does the CSS selector button:disabled select?
AButtons that are enabled
BButtons that are disabled
CAll buttons
DButtons with class 'disabled'
Which selector finds the first <li> element inside a <ul>?
Aul li:first-child
Bul li:last-child
Cul:first-child li
Dli:first-child ul
In Selenium Java, how do you select an input with attribute placeholder exactly 'Search'?
ABy.cssSelector("input[placeholder='Search']")
BBy.cssSelector("input[placeholder*='Search']")
CBy.cssSelector("input[placeholder^='Search']")
DBy.cssSelector("input[placeholder$='Search']")
What does the CSS selector a[href$='.pdf'] select?
ALinks with href starting with '.pdf'
BLinks with href containing '.pdf'
CLinks with href ending with '.pdf'
DAll links
Explain how CSS attribute selectors work and give examples of different operators.
Think about matching exact, starts with, ends with, and contains.
You got /3 concepts.
    Describe CSS pseudo-class selectors and how they help in selecting elements in Selenium tests.
    Focus on element states and positions.
    You got /3 concepts.