Selenium Interview Questions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

1. What is Selenium? What are the different Selenium components?

Selenium is one of the most popular automated testing suites. Selenium is designed in a way to support
and encourage automation testing of functional aspects of web-based applications and a wide range of
browsers and platforms

Selenium is one of the most popular open source free licensed automation tool for web applications

Its platform independent used for different os(desktop,linux,mac)

Applicable for different browsers

The suite package constitutes of the following sets of tools:

 Selenium Integrated Development Environment (IDE) – Selenium IDE is a record and playback
tool. It is applicable only for Firefox Plugin.
 Selenium Remote Control (RC) – Selenium RC is a server that allows a user to create test scripts
in the desired programming language. It also allows executing test scripts within the large
spectrum of browsers.
 Selenium Web Driver – Web Driver is a different tool altogether that has various advantages
over Selenium RC. Web Driver directly communicates with the web browser and uses its native
compatibility to automate.
 Selenium Grid – Selenium Grid is used to distribute your test execution on multiple platforms
and environments concurrently.

2) What are the limitations of Selenium?

Following are the limitations of Selenium:

 Selenium supports testing of only web-based applications


 Mobile applications cannot be tested using Selenium
 Captcha and Barcode readers cannot be tested using Selenium
 Reports can only be generated using third-party tools like TestNG or JUnit.
 As Selenium is a free tool, thus there is no ready vendor support though the user can find
numerous helping communities.
 The user is expected to possess prior programming language knowledge.

3) What are the different types of locators in Selenium?

The locator can be termed as an address that identifies a web element uniquely within the webpage. we
have different types of locators in Selenium:

 ID
 ClassName
 Name
 TagName
 LinkText
 PartialLinkText
 Xpath
 CSS Selector
 DOM

4. What is the difference between “/” and “//” in Xpath?

Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be created
to start selection from the document node/start node.

Double Slash “//” – Double slash is used to create Xpath with relative path i.e. the xpath would be
created to start selection from anywhere within the document.

5. How to retrieve css properties of an element?

The values of the css properties can be retrieved using a get () method:

Syntax:
driver.findElement (By.id (“id“)).getCssValue (“name of css attribute”);
driver.findElement (By.id (“id“)).getCssValue (“font-size”);

6. write a xpath using following sibling.

//input[@id=’name’]//following-sibling::label

7. How do I launch the browser using Web Driver?

The following syntax can be used to launch Browser:


WebDriver driver = new FirefoxDriver ();
WebDriver driver = new ChromeDriver ();
WebDriver driver = new InternetExplorerDriver ();

8. What are the different types of navigation commands?

Following are the navigation commands:


navigate ().back () – The above command requires no parameters and takes back the user to the
previous webpage in the web browser’s history.

Sample code:
driver.navigate ().back ();

navigate ().forward () – This command lets the user to navigate to the next web page with reference to
the browser’s history.

Sample code:
driver.navigate ().forward ();
navigate ().refresh () – This command lets the user to refresh the current web page there by reloading all
the web elements.

Sample code:
driver.navigate ().refresh ();

navigate ().to () – This command lets the user to launch a new web browser window and navigate to the
specified URL.

Sample code:
driver.navigate ().to (“https://google.com”);

9. What is the difference between driver.close () and driver.quit command?

close (): Web Driver’s close () method closes the web browser window that the user is currently working
on or we can also say the window that is being currently accessed by the WebDriver. The command
neither requires any parameter nor does is return any value.

quit (): Unlike close () method, quit () method closes down all the windows that the program has
opened. Same as close () method, the command neither requires any parameter nor does return any
value

10. Explain how to perform mouse actions using WebDriver.

WebDriver provides an Actions class for performing mouse actions like click, double click, right-click,
drag and drop, etc. You can use it like this:

Actions actions = new Actions(driver);

actions.click(element).perform();

11. What is the Page Object Model (POM), and why is it useful in Selenium WebDriver?

The Page Object Model is a design pattern that represents each web page as a Java class and stores the
locators and methods related to that page within the class. It promotes code reusability, maintainability,
and reduces code duplication in test scripts.

12. What is the PageFactory pattern, and how does it improve the Page Object Model (POM)?

The PageFactory pattern is used to initialize elements defined in a Page Object class. It improves the
POM by simplifying element initialization and making the code more readable and maintainable.
13. How do you handle dynamic elements or elements with changing attributes in Selenium WebDriver?

You can use dynamic XPath or CSS selectors that are based on the common, unchanging parts of the
element's attributes, or you can use relative XPath expressions to locate elements based on their
relationship to other elements.

14. What is the difference between WebDriver and WebElement in Selenium?

WebDriver is the interface used to interact with the web browser, while WebElement represents an
HTML element on a web page. WebDriver is responsible for navigating, managing the browser, and
locating web elements, whereas WebElement is used to interact with those elements.

15. What is TestNG, and why is it used in Selenium automation?

TestNG is a testing framework for Java that simplifies test case management and allows parallel test
execution, grouping, and reporting. It is often used in conjunction with Selenium for test automation.

16. What is the difference between getText() and getAttribute() in Selenium?

`getText()` is used to retrieve the visible text of an element, while `getAttribute()` is used to retrieve the
value of an element's attribute.

17. Explain how to capture screenshots in Selenium WebDriver.

You can capture screenshots using the `TakesScreenshot` interface and saving the screenshot to a file.

18. How do you handle browser cookies in Selenium WebDriver?

You can manage cookies using the `getCookies()`, `addCookie()`, and `deleteCookieNamed()` methods in
Selenium WebDriver.

19. What is the difference between getWindowHandle() and getWindowHandles() in Selenium?

`getWindowHandle()` returns the handle of the current window, while `getWindowHandles()` returns
a set of handles for all open windows. This is useful for switching between windows or tabs

20. What is the purpose of DesiredCapabilities in Selenium WebDriver?

DesiredCapabilities are used to specify the desired browser and platform configurations when working
with Selenium Grid.

21. What are the common exceptions in Selenium WebDriver and how can you handle them?

Common exceptions include `NoSuchElementException`,’ ElementNotVisibleException’,’


ElementNotSelectableException’, `TimeoutException`,’ InvalidSelectorException’,’
NoAlertPresentException’,’ NoSuchWindowException’ etc. You can handle them using try-catch blocks,
waits, or retry mechanisms.
22. How do you handle different types of pop-up windows (e.g., alerts, prompts, and confirmations) in
Selenium WebDriver?

You can handle pop-up windows using the `Alert` class methods in Selenium WebDriver.

23. How can you handle synchronization issues in Selenium automation?

Synchronization can be achieved using waits, such as `Thread.sleep()`, `ImplicitWait`, and


`ExplicitWait`, to ensure that elements are available before performing actions.

24. What is Software development life cycle?

*Requirement
*Feasibility
*Design
*Coding
*Testing
*Installation
*Maintance

25. What is Software testing life cycle?

*System Study

*Test plan

*Test document

*R.T.M document

*Test Execution

*Defect tracking

*Text execution report

*Retrospect/Postman meeting

26. Explain the defect life cycle.

The defect life cycle typically includes stages like:


- New (when a defect is initially reported)

- Open (when it's confirmed and assigned)

- In Progress (while it's being fixed)

- Fixed (when the developer believes it's resolved)

- Verified (when the tester confirms the fix)

- Closed (when it's officially closed)

27. What is TestNG, and why is it used in Selenium automation?

TestNG is a testing framework for Java that simplifies test case management and allows parallel test
execution, grouping, and reporting. It is often used in conjunction with Selenium for test automation.

28. What is a TestNG annotation, and how is it used in Selenium testing?

TestNG annotations are used to control the flow and execution of test cases. Annotations like `@Test`,
`@BeforeSuite`, `@AfterMethod`, etc., are used to specify test methods, setup, and teardown methods.

29. How to read excel data in selenium


HSSFWorkbook– Methods of this class are used to read or write data to Microsoft Excel file in .
xls format.

 Workbook: XSSFWorkbook and HSSFWorkbook classes implement this interface.


 XSSFWorkbook: Is a class representation of XLSX file.
 HSSFWorkbook: Is a class representation of XLS file.
 Sheet: XSSFSheet and HSSFSheet classes implement this interface.

30. Different Testing Levels supported by Selenium

 Smoke Testing.
 Sanity Testing.
 UI Testing.
 Database Testing.
 Cross Browser Testing.
 Regression Testing.

31) difference between Whitebox testing and Blackbox testing?

White box testing


*Its done by developer

*look into source code and test the logic of the code

*Should have knowledge of internal design of the code

*Should have knowledge off programming

Black box testing:

*Its done by testing engineer

*verify the functionality of application

*No need to have knowledge of internal design of the code

*No need to have knowledge off programming

You might also like