Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find an element by its CSS selector.
Selenium Python
element = driver.find_element_by_css_selector([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to add '#' before the id in the selector.
Using a class selector '.' instead of id selector '#'.
✗ Incorrect
The CSS selector for an element with id 'submit-button' must start with '#'.
2fill in blank
mediumComplete the code to find an element with class 'menu-item' using CSS selector.
Selenium Python
element = driver.find_element_by_css_selector([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name without '.' prefix.
Using '#' which is for id selectors.
✗ Incorrect
To select by class in CSS selector, use '.' before the class name.
3fill in blank
hardFix the error in the code to find an element by CSS selector for a button with class 'btn-primary'.
Selenium Python
element = driver.find_element_by_css_selector([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name without '.' prefix.
Using id selector '#' instead of class selector '.'
✗ Incorrect
The correct CSS selector for class 'btn-primary' is '.btn-primary'.
4fill in blank
hardFill both blanks to find an input element with type 'text' using CSS selector.
Selenium Python
element = driver.find_element_by_css_selector("input[[1]='[2]']")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping attribute name and value.
Using 'name' instead of 'type' for the first blank.
✗ Incorrect
The selector input[type='text'] finds input elements with type attribute equal to 'text'.
5fill in blank
hardFill all three blanks to find a button element with class 'btn' and text 'Submit' using CSS selector.
Selenium Python
element = driver.find_element_by_css_selector("button.[1]:contains('[2]')") # Note: :contains is not standard CSS # Alternative: find by class and then check text separately button = driver.find_element_by_css_selector("button.[3]")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class name without '.' prefix.
Trying to use :contains which is not supported in Selenium CSS selectors.
✗ Incorrect
The CSS selector 'button.btn' selects button elements with class 'btn'. The :contains pseudo-class is not standard in CSS, so text matching is done separately.