0
0
Selenium Javatesting~10 mins

Network interception (CDP) 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 create a CDP session for network interception.

Selenium Java
DevTools devTools = driver.[1]();
Drag options to blanks, or click blank then click option'
AgetDevTools
BopenDevTools
CstartDevTools
DcreateDevTools
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not exist like createDevTools or startDevTools.
2fill in blank
medium

Complete the code to enable the Network domain in CDP.

Selenium Java
devTools.send(Network.[1]());
Drag options to blanks, or click blank then click option'
Aenable
Bdisable
Cstart
Dactivate
Attempts:
3 left
💡 Hint
Common Mistakes
Using disable or start which are not valid commands for Network domain.
3fill in blank
hard

Fix the error in the code to add a listener for network requests.

Selenium Java
devTools.addListener(Network.[1], request -> {
    System.out.println("Request URL: " + request.getRequest().getUrl());
});
Drag options to blanks, or click blank then click option'
ArequestSent
BonRequest
CrequestWillBeSent
DnetworkRequest
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect event names that do not exist in the Network domain.
4fill in blank
hard

Fill both blanks to create a map of headers to modify a network request.

Selenium Java
Map<String, Object> headers = new HashMap<>();
headers.put("[1]", "application/json");
headers.put("[2]", "no-cache");
Drag options to blanks, or click blank then click option'
AContent-Type
BCache-Control
CAccept
DAuthorization
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing header names or using headers unrelated to content type or caching.
5fill in blank
hard

Fill in the blanks to modify and continue a network request with new headers.

Selenium Java
devTools.addListener(Network.requestIntercepted(), request -> {
    Map<String, Object> headers = new HashMap<>(request.getRequest().getHeaders());
    headers.put("[1]", "Bearer token123");
    devTools.send(Network.[2](request.getInterceptionId(), headers));
});
Drag options to blanks, or click blank then click option'
AAuthorization
BcontinueInterceptedRequest
CcontinueRequest
DsetRequestHeaders
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect header names or wrong Network commands to continue the request.