0
0
Selenium Javatesting~10 mins

Cookie management in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a cookie named "session" with value "abc123".

Selenium Java
Cookie cookie = new Cookie("session", [1]);
driver.manage().addCookie(cookie);
Drag options to blanks, or click blank then click option'
A"session"
B"abc123"
C"cookie"
D"123abc"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the cookie name as the value.
Using incorrect string values.
2fill in blank
medium

Complete the code to delete a cookie named "userToken".

Selenium Java
driver.manage().deleteCookieNamed([1]);
Drag options to blanks, or click blank then click option'
A"userToken"
B"cookie"
C"token"
D"user"
Attempts:
3 left
💡 Hint
Common Mistakes
Using partial or incorrect cookie names.
Forgetting to use quotes around the cookie name.
3fill in blank
hard

Fix the error in the code to get a cookie named "sessionId".

Selenium Java
Cookie cookie = driver.manage().[1]("sessionId");
Drag options to blanks, or click blank then click option'
AgetCookieName
BgetCookie
CgetCookieNamed
DgetCookieByName
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names that do not exist.
Confusing method names with similar words.
4fill in blank
hard

Fill both blanks to create and add a cookie with name "auth" and value "token123".

Selenium Java
Cookie [1] = new Cookie([2], "token123");
driver.manage().addCookie(authCookie);
Drag options to blanks, or click blank then click option'
AauthCookie
B"auth"
C"authCookie"
Dcookie
Attempts:
3 left
💡 Hint
Common Mistakes
Using the cookie name as variable name without quotes.
Using quotes for variable name.
5fill in blank
hard

Fill all three blanks to create a cookie map with cookie names as keys and values as values, filtering only cookies with names longer than 4 characters.

Selenium Java
Map<String, String> cookieMap = driver.manage().getCookies().stream()
    .filter(c -> c.getName().length() [1] 4)
    .collect(Collectors.toMap([2], [3]));
Drag options to blanks, or click blank then click option'
A>
Bc -> c.getName()
Cc -> c.getValue()
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in filter.
Swapping key and value in toMap.
Using incorrect lambda syntax.