Hands-On Selenium
& API Automation
By Rupendra Kumar Ragala
Selenium Automation Questions
1. How to handle a dropdown in Selenium?
Explanation: Use the Select class to handle dropdowns.
selectByVisibleText selects the option based on visible text.
2. How to handle multiple windows in Selenium?
Explanation: This switches to a new window, performs actions,
and then returns to the main window.
3. Write a code to capture a screenshot in Selenium.
Explanation: The TakesScreenshot interface allows capturing
screenshots and saving them to the specified path.
4. How to handle alerts in Selenium?
Explanation: The switchTo().alert() handles JavaScript alerts,
and accept() closes it.
5. How do you perform drag and drop in Selenium?
Explanation: The Actions class handles complex actions like
drag-and-drop, mouse movements, etc.
6. Write code to handle frames in Selenium.
Explanation: This switches to a frame by name, performs
actions, and then returns to the main content.
7. How to handle cookies in Selenium?
Explanation: Adds and retrieves cookies from the browser.
8. How do you handle exceptions in Selenium?
Explanation: Uses try-catch to handle NoSuchElementException
when an element isn't found.
9. How to verify if an element is displayed?
Explanation: Checks if the element is displayed on the page
using isDisplayed().
10. How to execute JavaScript in Selenium?
Explanation: Executes JavaScript to scroll the page down by
1000 pixels.
11. How to check for broken links on a webpage?
Explanation: Loops through all anchor tags, checks if links are
working using HttpURLConnection.
12. How do you wait for an element to be visible in Selenium?
WebDriverWait wait = new WebDriverWait(driver,
Duration.ofSeconds(10));
WebElement element =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(
"elementId")));
13. How to perform mouse hover action in Selenium?
Explanation: The Actions class helps simulate a mouse hover
over a specific element.
14. How to handle a file upload in Selenium?
Explanation: Use sendKeys to send the file path directly to the
file input element for uploading.
15. How to scroll to the bottom of the page in Selenium?
Explanation: This JavaScript command scrolls the page to the
bottom, useful when loading more elements dynamically.
16. How do you handle right-click (context click) in Selenium?
Explanation: The Actions class's contextClick method performs
a right-click action on an element.
17. How to capture and print all links on a webpage?
Explanation: This finds all anchor tags and prints their href
attributes, which contain the URLs.
API Automation Questions
1. How to send a GET request and validate status code using
RestAssured?
Explanation: RestAssured framework allows sending requests
and validating responses in a single line.
2. Write a POST request code to create a new user in
RestAssured.
Explanation: The code sends a JSON body with user data and
checks if the response has a 201 status code.
3. How to validate a JSON response field in RestAssured?
Explanation: Validates the email field in the JSON response
using a JSON path.
4. Write a code to add headers in a RestAssured request.
Explanation: Adds Content-Type and Authorization headers to
the request.
5. How to validate response time in an API request?
Explanation: Checks if the response time is less than 2 seconds.
6. Write code to verify if a response contains a particular JSON
field.
Explanation: This checks if the response JSON has a "data" key.
7. How to send a PUT request using RestAssured?
Explanation: Sends a PUT request with JSON data to update a
user’s information.
8. How to handle pagination in an API request?
Explanation: Continues requesting pages until there are no
more records, printing each page's users.
9. How to verify a JSON array size in a response?
Explanation: This checks if the "data" JSON array in the response
contains exactly six items.
10. Write a code to extract specific data from a JSON response
in RestAssured.
Explanation: The jsonPath() method allows extracting specific
data fields from a JSON response.
11. How to send a DELETE request using RestAssured?
Explanation: This sends a DELETE request to remove a user
resource, expecting a 204 No Content status.
12. How to validate a specific header in an API response?
Explanation: This checks if the Content-Type header in the
response matches the expected value.
13. How to handle query parameters in RestAssured?
Explanation: The queryParam method allows passing query
parameters (like page=2) in the request URL.
14. How to handle basic authentication in an API request using
RestAssured?
Explanation: This handles basic authentication by providing a
username and password.
15. How to send a PATCH request to update partial data in
RestAssured?
Explanation: PATCH requests update only specific fields in the
existing resource without overwriting the entire record.
16. How to add multiple query parameters in a single request?
Explanation: Multiple query parameters can be added using
repeated queryParam calls.
17. How to check if a response JSON path returns a non-null
value?
Explanation: The notNullValue() matcher ensures that the
data.email path is not null.
18. How to send form parameters in RestAssured?
Explanation: Form parameters are often used in requests where
data is sent in application/x-www-form-urlencoded format.
Thank You