Introduction
This quiz is designed for beginners who are looking to test their knowledge of Selenium, a popular automation testing tool for web applications. These multiple-choice questions will help you understand the basics of Selenium and its various components.
1. What is Selenium primarily used for?
Answer:
Explanation:
Selenium is an open-source tool for automating web browsers. It provides a single interface for writing test scripts in programming languages such as Ruby, Java, NodeJS, PHP, Perl, Python, and C#.
2. Which programming language is not supported by Selenium?
Answer:
Explanation:
Selenium does not have official bindings for PHP, although third-party libraries exist.
3. What is the role of the Selenium WebDriver
?
Answer:
Explanation:
Selenium WebDriver
is used to interact with web browsers, enabling automation of web tasks.
4. What is Selenium IDE
?
Selenium Grid
Answer:
Explanation:
Selenium IDE
is a browser extension for recording and playing back user interactions with a web application.
5. Which component of Selenium is used for distributed testing?
Selenium WebDriver
Selenium IDE
Selenium Grid
Selenium RC
Answer:
Selenium Grid
Explanation:
Selenium Grid
is used to run tests on different machines and browsers simultaneously, enabling distributed testing.
6. Which Selenium component was deprecated and replaced by WebDriver
?
Selenium Grid
Selenium IDE
Selenium RC
Selenium Server
Answer:
Selenium RC
Explanation:
Selenium RC
(Remote Control) was deprecated in favor of Selenium WebDriver
, which is more efficient and user-friendly.
7. Which method is used to open a URL in Selenium WebDriver
?
get()
open()
launch()
start()
Answer:
get()
Explanation:
The get()
method is used in Selenium WebDriver
to open a specified URL in the browser.
8. What is the purpose of the findElement()
method in Selenium WebDriver
?
Answer:
Explanation:
The findElement()
method is used to locate a web element on a page so that actions can be performed on it.
9. Which command is used to close the current browser window in Selenium WebDriver
?
quit()
close()
exit()
stop()
Answer:
close()
Explanation:
The close()
method is used to close the current browser window that WebDriver
is controlling.
10. What does the quit()
method do in Selenium WebDriver
?
WebDriver
WebDriver
serverAnswer:
WebDriver
Explanation:
The quit()
method closes all browser windows opened during the WebDriver
session and ends the WebDriver
session.
11. What is the use of the sendKeys()
method in Selenium WebDriver
?
Answer:
Explanation:
The sendKeys()
method is used to simulate typing into a text field or any other input field in a web form.
12. Which of the following is NOT a valid WebDriver
method?
findElement()
click()
select()
getCurrentUrl()
Answer:
select()
Explanation:
There is no select()
method in WebDriver
. To select dropdown options, we use the Select
class in Selenium.
13. How can you handle multiple windows in Selenium WebDriver
?
getWindowHandles()
getCurrentWindow()
getAllWindows()
getActiveWindow()
Answer:
getWindowHandles()
Explanation:
The getWindowHandles()
method is used to handle multiple windows in Selenium by returning a set of window handles.
14. Which method is used to switch to an iframe
in Selenium WebDriver
?
switchTo().frame()
switchTo().iframe()
switch().toFrame()
switchFrame()
Answer:
switchTo().frame()
Explanation:
The switchTo().frame()
method is used to switch the WebDriver
's context to a specific iframe
within the web page.
15. Which method is used to handle alerts in Selenium WebDriver
?
switchTo().alert()
getAlert()
alert().switch()
handleAlert()
Answer:
switchTo().alert()
Explanation:
The switchTo().alert()
method is used to handle JavaScript alerts, prompts, and confirmations in Selenium WebDriver
.
16. How can you select a dropdown value in Selenium WebDriver
?
selectByValue()
selectValue()
chooseValue()
setValue()
Answer:
selectByValue()
Explanation:
The selectByValue()
method is used to select a dropdown option based on its "value" attribute in Selenium WebDriver
.
17. Which method is used to wait until an element is visible in Selenium WebDriver
?
implicitlyWait()
waitForElement()
waitUntilVisible()
waitForVisibleElement()
Answer:
implicitlyWait()
Explanation:
The implicitlyWait()
method is used to instruct WebDriver
to wait for a certain amount of time before throwing an exception if an element is not found.
18. What is the purpose of WebDriver
's manage().timeouts().implicitlyWait()
method?
Answer:
Explanation:
The manage().timeouts().implicitlyWait()
method sets a maximum time WebDriver
will wait for an element to be available before throwing an exception.
19. Which method is used to select an option from a dropdown by visible text in Selenium WebDriver
?
selectByText()
selectByVisibleText()
selectByOption()
selectByLabel()
Answer:
selectByVisibleText()
Explanation:
The selectByVisibleText()
method is used to select a dropdown option based on the text visible to the user.
20. What does the WebDriver
's executeScript()
method do?
Answer:
Explanation:
The executeScript()
method is used to execute JavaScript in the context of the current browser page in Selenium WebDriver
.
21. Which of the following is a locator strategy in Selenium WebDriver
?
By.className()
By.src()
By.image()
By.type()
Answer:
By.className()
Explanation:
By.className()
is one of the locator strategies used to locate elements in Selenium WebDriver
.
22. Which Selenium class is used to handle dropdowns in WebDriver
?
Dropdown
Select
Option
Choose
Answer:
Select
Explanation:
The Select
class in Selenium WebDriver
is used to handle dropdown elements on a web page.
23. Which method is used to navigate back to the previous page in Selenium WebDriver
?
navigate().back()
goBack()
previous()
return()
Answer:
navigate().back()
Explanation:
The navigate().back()
method is used to go back to the previous page in the browser's history in Selenium WebDriver
.
24. Which Selenium WebDriver
method is used to clear the content of a text field?
clear()
reset()
erase()
delete()
Answer:
clear()
Explanation:
The clear()
method is used to clear the content of a text field in Selenium WebDriver
.
25. Which Selenium WebDriver
method is used to maximize the browser window?
maximize()
window().maximize()
expand()
fullscreen()
Answer:
window().maximize()
Explanation:
The window().maximize()
method is used to maximize the browser window in Selenium WebDriver
.
26. What does the WebDriverWait
class do in Selenium WebDriver
?
Answer:
Explanation:
The WebDriverWait
class in Selenium WebDriver
is used to wait until a certain condition is met before proceeding with the next step.
27. Which method is used to perform a mouse hover action in Selenium WebDriver
?
moveToElement()
hover()
mouseHover()
mouseOver()
Answer:
moveToElement()
Explanation:
The moveToElement()
method is used to perform a mouse hover action on a web element in Selenium WebDriver
.
28. Which of the following is NOT a valid way to locate elements in Selenium WebDriver
?
By.id()
By.name()
By.data()
By.xpath()
Answer:
By.data()
Explanation:
By.data()
is not a valid locator strategy in Selenium WebDriver
. Valid strategies include By.id()
, By.name()
, and By.xpath()
.
29. How do you switch to a new browser window in Selenium WebDriver
?
switchTo().window()
switchTo().newWindow()
navigate().toNewWindow()
getNewWindow()
Answer:
switchTo().window()
Explanation:
The switchTo().window()
method is used to switch control to a new browser window in Selenium WebDriver
.
30. What does the WebDriver
's getTitle()
method do?
Answer:
Explanation:
The getTitle()
method in Selenium WebDriver
is used to retrieve the title of the current web page.
31. What is the purpose of the WebDriver
's getPageSource()
method?
Answer:
Explanation:
The getPageSource()
method in Selenium WebDriver
is used to fetch the entire HTML source code of the current web page.
32. What is the primary use of the WebDriver
's getWindowHandle()
method?
Answer:
Explanation:
The getWindowHandle()
method is used to return the unique identifier (handle) of the current browser window in Selenium WebDriver
.
33. Which WebDriver
method is used to check if an element is displayed on a webpage?
isDisplayed()
isVisible()
isPresent()
isShown()
Answer:
isDisplayed()
Explanation:
The isDisplayed()
method is used in Selenium WebDriver
to check if a web element is visible on the web page.
34. How can you simulate a right-click action in Selenium WebDriver
?
contextClick()
methodrightClick()
methodclickRight()
methodmouseRightClick()
methodAnswer:
contextClick()
methodExplanation:
The contextClick()
method in Selenium WebDriver
is used to simulate a right-click action on a web element.
35. What does the WebDriver
's getText()
method return?
Answer:
Explanation:
The getText()
method in Selenium WebDriver
is used to retrieve the inner text of a web element.
Conclusion
This quiz provided a basic understanding of Selenium's functionalities and components. By answering these questions, you should now understand how Selenium works and how it can be used in web application testing.
Comments
Post a Comment
Leave Comment