Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a cookie named 'user' with value 'admin'.
Selenium Python
driver.add_cookie({"name": "user", "value": [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the cookie name as the value.
Forgetting to put the value in quotes.
✗ Incorrect
The cookie value must be a string. Here, 'admin' is the correct value for the 'user' cookie.
2fill in blank
mediumComplete the code to delete a cookie named 'session_id'.
Selenium Python
driver.delete_cookie([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong cookie name.
Not using quotes around the cookie name.
✗ Incorrect
To delete a specific cookie, you must provide its exact name. Here, 'session_id' is the cookie to delete.
3fill in blank
hardFix the error in the code to get a cookie named 'token'.
Selenium Python
cookie = driver.get_cookie([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the cookie name without quotes.
Using a variable name instead of a string.
✗ Incorrect
The get_cookie method requires the cookie name as a string with quotes. Without quotes, it causes an error.
4fill in blank
hardFill both blanks to check if a cookie named 'auth' exists and print its value.
Selenium Python
cookie = driver.get_cookie([1]) if cookie is not [2]: print(cookie['value'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking against False instead of None.
Using wrong cookie name or missing quotes.
✗ Incorrect
get_cookie needs the cookie name as a string. The check must be against None to see if the cookie exists.
5fill in blank
hardFill all three blanks to add a cookie with name 'theme', value 'dark', and path '/app'.
Selenium Python
driver.add_cookie({"name": [1], "value": [2], "path": [3]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong path or missing quotes.
Mixing up name and value.
✗ Incorrect
The cookie dictionary must have the correct name, value, and path as strings. Here, 'theme', 'dark', and '/app' are correct.