Selenium Java Interview

The crucial phase in the software development life cycle (SDLC) is Testing. There are two types of Testing.

  1. Manual Testing
    1. It involved the physical execution of test case scenarios against the applications to detect the errors and bugs.
    2. This posed a lot of challenges and heavy manual effort.
  2. Automation Testing
    1. On the other hand, Automation Testing provided us a way to automate the testing processes and increased the demand.

In midst of all this, questions do arise like What is Selenium? Why is it important and so on.

Selenium is an open-source, automated testing tool which is used to test the web applications across various browsers. However, the sad part is, it can test only web applications and not the mobile and desktop applications.

Some of the leading browser vendors adopted Selenium as the essential part of their browser and thus leading to an increase in high demand for this.

The entire set of Selenium interview questions includes two sections.

  1. Basic Selenium interview questions for freshers
  2. Selenium interview questions for experienced professionals

If you all are geared up, we shall dive into the Most asked interview questions on Selenium.

Here we go,

Selenium Interview Questions

  1. What is Automation Testing?

The use of automation tools for writing and executing the test cases with no manual involvement for executing the Automated Test Suite is called Automation Testing. The Automation tools are preferred by Testers to write the test cases or test scripts and then group them all into Test Suites. These tools are designed to execute manually designed test cases without any human intervention. 

  1. What are the advantages/benefits of Automation Testing?

This is one of the common interview questions. Some of the advantages of Automation Testing include:

  • Save Money and Time. 
  • Automation Testing increases the accuracy as there is no chance for human errors.
  • Code Reusability. Create once and execute multiple times with Less or no maintenance.
  • Easy Reporting. Automatically generates the reports after the execution of the test cases.
  • Easy for Compatibility Testing by enabling the parallel execution in combination with OS and browser environments.
  • More Reliable, Powerful and Versatile.
  • Automation Tools allows us to integrate with the Jenkins, GitHub etc.,
  • Mostly used for Regression Testing.
  • Helps to monitor the Test Coverage and increase the test cases accordingly.
  1. What is Selenium?

Selenium is one of the most popular automated Testing Suite. It’s a playback tool to perform the functional testing without any knowledge of a test scripting language. Selenium is the open-source, web UI based automation testing suite. Jason Huggins developed this tool in 2004 at ThoughtWorks. 

  1. What are the different Selenium suite Components?

Selenium is not just a single tool or utility, rather a package of several testing tools and that’s why it’s called Selenium Suite. Each of these tools caters to different testing and testing environments.

It comprises four major components as follows,

  1. Selenium Integrated Development Environment (IDE):

It is distributed as a Firefox plugin which acts as a record and playback tool. It is developed to speed up the creation of automation scripts.

  1. Selenium Remote Control (RC):

Selenium Remote Control is a server with which the user can create the Test cases in any desired programming language. The commands present in the test scripts are accepted by the server and sent to the browsers as the Selenium core Java script commands to maintain the browser behaviour accordingly.

  1. Selenium Web driver:

Selenium Web Driver is a programming interface to create and run the test cases. It provides a way to act on various web elements. This Web driver does not require another server, unlike Selenium Remote Control.

  1. Selenium Grid:

The Selenium Grid is used to distribute the commands to the different machines simultaneously. It paves a way for the parallel execution of the test cases in different browsers and different environments. It achieves concurrency and integrity in the Test Suite Execution.

  1. Why should I use Selenium?
  • Open-source
  • Large support from the community and the user base is huge
  • Cross-browser compatibility (Firefox, Chrome, Edge etc.,)
  • Multiple programming language support (Python, Java, Perl etc.,)
  • Every day or regular repository developments
  • Distributed Testing is also supported.
  1. What are the challenges and Limitations of the Selenium Web Driver?

As we all know that the Selenium Web Driver is used to mimic the real user actions on the web in the browser. Some of the challenges of Selenium are as follows,

  1. Not compatible to test the Windows or Desktop applications.
  2. Also, cannot be used to test the Mobile applications.
  3. No Built-in reporting and it must be integrated with the other tools to obtain the reports.
  4. Support for Image Testing is limited.
  5. The user should have prior programming knowledge.
  6. Since it is open-source, there is no vendor support.
  7. What are the Testing types that are supported by Selenium?

Regression Testing and Functional Testing are majorly supported by Selenium.

  1. Regression Testing:

All the Test cases are executed repeatedly either partially or as a full to ensure that the existing functionalities are working as designed. It includes the following steps,

  • Re-testing: All the test cases in the Test Suite are executed which proves to be time-consuming and expensive.
  • Regression Test case Selection: The test cases are classified or categorized as features tests, integration tests etc., and some test cases are selected.
  • Prioritization of Test cases: The test cases that are selected are prioritized based on the critical functionalities and business impact.
  1. Functional Testing:

In this, all the functions in the application are verified with a specific requirement. This is primarily the black-box testing as it is not concerned about the source code of the application. It includes the following steps,

  • Test Input is identified.
  • Test Outcome is computed.
  • The test case is executed
  • The actual outcome and the test outcome are compared accordingly.
  1. What is the major difference between Selenium 3.0 and Selenium 2.0?

Selenium 2.0 represents the merger of the Original Selenium project with the Web Driver project. Selenium RC got deprecated but was used for backward compatibility.

Selenium 3.0 often called an extension of the Selenium 2.0 is inherently backwards compatible with increased stability and several bug fixes and does not involve the Selenium RC at all.

  1. How many Test cases have you automated per day?

This is one of the tricky Selenium interview questions. Actually, it depends on the complexity and length of the Test case scenario. When the complexity is limited, you can automate two-five test cases and one or fewer test cases when the complexity is high in a day.

  1. What do you mean by Selenese?

Selenese which is called the Selenium command is the set of the selenium commands that run your test cases. For example, open (URL) is a Selenium command which opens the specified URL in the specific browser. A test script is the sequence of all these commands put together. There are three types of Selenese. They are,

  1. Actions: We can use it to perform interactions and operations on the target elements
  2. Accessors: These are used for storing the values in the variables.
  3. Assertions: These can be used as checkpoints to keep track of the sequential flow of commands.
  4.  How many parameters do selenium commands have at a minimum?

There are four parameters that you must pass in Selenium. They are as follows,

  • Host

We can bind the Selenium to a specific IP address instead of Local host in our local machine.

  • Port Number

We can specify the port number too i.e., TCP/IP port to connect the Selenium tests to the Grid hub. We need to make sure that there is no other application with the same port number up in any other location within the same machine.

  • Browser

The browser in which the selenium scripts have to be executed.

  • URL

The application URL to trigger the test cases within that.

  1.  What is the difference between the Absolute path and the Relative Path?

Absolute Path: 

  • This path starts from the root node and ends with the desired elements node.
  • It starts with a single slash (/)
  • Example: /html.body/div/td/input

Relative Path:

  • This path starts from any node in between and to the desired elements node.
  • It starts with a double slash (//)
  • Example: //input/example[@id=name]
  1. What is the difference between Assert and Verify statements in Selenium?

Assert:

  • We can check whether an element is on the page or not.
  • The test fails and gets terminated whenever there is a fail in the check. That is the program control flow stops.

Verify:

  • It’s only to specify whether the given condition is true or false.
  • The program control flow does not stop due to this.

Overall, the Verify statement does not halt the program execution whereas the Assert statement does halt the execution. 

  1.  What is the difference between findElement() and findElements()?

findElement() : 

It uses the given locating mechanism to find the first element within the current page and return a single web element.

findElements():

It also uses the given locating mechanism to find all the elements within the current page and return the list of all web elements.

  1.  What are the verification points that are available in Selenium?
  • Selenium IDE: Verify and Assert commands
  • Selenium Web Driver: This does not have any built-in features for verification and always depends on our coding style. Some examples can be like checking the page title, checking for certain text in the page, checking for a certain element like textbox, dropdown, field etc.,
  1.  Explain different types of Exceptions in Selenium Web driver?

The Exceptions in Selenium web driver are also similar to the exceptions in any other programming language like Java, C# etc., Some of the most common exceptions are as follows,

  • TimeOutException: This exception can be thrown when a particular operation cannot be completed in a specified or stipulated time.
  • NoSuchElementException: When an element in the given set of attributes is not present on the web page then, this exception can be thrown.
  • ElementNotVisibleException: There can be cases where a particular element can be present in the DOM (Document Object Model) but not visible on the web page. In such cases, this exception can be thrown.
  • StaleElementException: When an element is either deleted or no longer present in the DOM then, this exception can be thrown. We generally face this exception when the element we are interacting with is either destroyed or recreated again. 
  1.  Explain Implicit wait, Explicit wait and Fluent wait?
  • Implicit wait:

We can set the timeout for a specific amount of time for all the successive web elements. In this specified time, web driver searches for all the web elements before throwing the NoSuchElementException. 

  • Explicit wait:

We can tell the Web Driver to wait for certain conditions before throwing the ElemntNotVisibleException.

  • Fluent wait:

It’s a slight extension for the explicit wait. Apart from waiting for certain conditions to be met, we can also set the frequency with which we to check the condition before throwing the ElementNotVisibleException.

  1.  What is the major difference between driver.close() and driver.quit()?

driver.close():

It’s a command by which the current window can be closed. For example, if we have multiple browser windows open then, by using this command we can close the window with which the focus is.

driver.quit():

This command closes all the browser windows which are open. For example, if we have multiple browser windows open then, this command can close all the windows at once.

  1.  Can Selenium handle windows-based pop-up?

As we already know that Selenium is the automation testing tool that can work with only web applications. Therefore, the pop-up in windows cannot be handled by Selenium. But, by integrating with the third-party tools we can overcome this problem.

  1.  What is an Object Repository and Explain how we can create the Object Repository in Selenium?

The collection of web elements that belongs to the application under test along with their locator values. This is often referred to as Object Repository. The only thing is the locators are stored in a centralized location than hard coding them in the test scripts.

While coming to Selenium, the objects can be stored in Excel also and can be used to populate them in the script whenever required. 

  1. What are the different kinds of frameworks?
  • Data-driven framework:

The test data in this kind is generated from external files like excel, CSV, XML etc., The data related to the test cases rely outside on. The input and verification values are maintained using the variables.

  • Keyword-driven framework:

The data tables and the keywords are developed independently of the automation test cases. In this framework, the functionality of the test scenarios is documented in the table step by step.

  • Module-based testing framework:

Isolated and Logical modules are made out of the application that is under test. Independent test scripts are written for each module. These scripts are then clubbed together as a whole.

  • Behaviour driven testing framework:

The test scripts are written in such a way that the automation is done on the functionality or features to ensure the readability, understanding and the reliability to either the business experts or developers or other testers.

  • Hybrid testing framework:

The combination of more than one of the above mentioned frameworks by leveraging the benefits of each is called as Hybrid testing framework.

  1.  What is the same-origin policy? How can we avoid it?

This policy is introduced for security reasons.

  • By this policy, it ensures that we cannot access the script from another site.
  • The source code which is loaded within the browser can only be operated within that website’s domain.
  • This policy can be avoided by using the proxy-injection method. In this method, the browser is tricked using the Selenium’s server to be a real URL (fictional URL).
  1. What is the difference between the getwindowhandle() and getwindowhandles()?

getwindowhandles(): This is used to get the address of all the open browsers and returns the data type of Set<String>.

getwindowhandle(): This is used to get the address of the current browser window where it’s focused on and returns the data type of String.

  1. What are the different types of Annotations used in Selenium?

Syntactic metadata can be added to the Java source code which is known as annotations. They can be added on variables, parameters, packages, classes etc., Some of them which are used in Selenium include,

@Before, @Test, @After

  1. What is the difference between setSpeed() and sleep() methods?

These methods will delay the speed of the execution. 

Thread.sleep(): The current thread will stop for a specified period of time. It only waits once when the command is given. It takes only a single argument that is Integer format.

set sleep(): This command will stop the execution for every selenium command. This command is used only for demonstration purposes and also for a slow web application.

  1. List the advantages of Web driver over Selenium server?
  • If Selenium web driver is used, then no need to use the dependency of the selenium server.
  • Selenium server provides us with the functionality of Selenium RC for the backward compatibility.
  • Selenium server acts as a middleware for the communication between browsers and the application. Whereas, the Selenium web driver directly calls the browser to support automation.
  1. How can you store a value in a text box?

A command which can store the value from text box using a web driver.

For example, 

driver.findElement(By.id(“your Textbox”)).sendKeys(“your keyword”);

  1.  Can you explain how can you handle colours in web driver?

We can use the command getCssValue(arg0) to fetch the colours by sending the colour as the argument.

  1. Which implementation of the web driver is the fastest?

The web driver implementation HTML Unit Driver is the fastest of all. This is because this driver does not execute the tests in the browser but rather, executes only the plain HTTP which is quick faster as expected.

  1. How can you debug the tests in the Selenium IDE?
  • We need to first insert the breakpoints where we need to debug and execute the test step by step. 
  • Later, Run the test case.
  • After this, the execution stops at the point where the breakpoint is kept.
  • You can click on the Run button to continue the execution of all the commands sequentially.
  1. What are regular expressions and How can you use regular expressions in Selenium?

The Search patterns are represented using the special Text string called the regular expressions. Regexp is the keyword that can be used as a prefix to treat a text in Selenium as a regular expression.

  1. How can you handle working with multiple windows in Selenium?

selectWindow() command in Selenium can be used to switch among the working windows. The distinguishing factor among all the windows is the title of the window.

  1. How can the message in the alert box be retrieved?

storeAlert() command can be used to retrieve the message from the alert pop-up and store it in a variable.

  1.  How can you verify the specific position of a web element?

verifyElementPositionLeft and verifyElementPositionTop commands are used. These use the pixel comparison by identifying the position of the element from the left and top of the web page respectively.

  1.  Why do we use Selenium RC?
  • Selenium IDE has the limitations which Selenium RC can diminish in terms of browser support and language support.
  • IDE does not support many functions like Logging, iterations, conditional statements, test case results reporting etc., as it supports only HTML Language.
  • That’s why the Selenium RC is used to communicate with the other languages like Perl, Python etc.,
  1.  What are the advantages or Benefits of Selenium RC?

Advantages or Benefits of RC include,

  • Data can be read or write to or from .xlsx, .csv, .txt etc.,
  • Dynamic objects and Ajax based UI elements can be handled.
  • Conditional statements and Iterations functionalities can be used to improve and enhance performance and flexibility.
  • Support for any programming languages and Operating systems.
  • Selenium RC can be used on any browser which is enabled with Java script.
  1. Can you list the Technical limitations while using the Selenium RC?
  • Same origin policy
  • Anything outside the browser is also restricted to access in the test scenario execution.
  1. What is the need to use the TestNG with Selenium RC?

If the requirement of the automation test suite is supposed to work against the different servers and client platforms then, we need to invoke the test cases from the command line. Also, we do need the test case results reports periodically to make estimates and also implement the flexibility on how to create the tests. Such kind of flexibility is provided by the TestNG.

  1.  Which Language do you use to implement test case suites in Selenium?

The most preferred language to implement Selenium in Python over Java. This is because,

  • Java programs do run slower when compared to the Python programs.
  • The implementation and the complexity of both are quite different and Python works well.
  • Python is dynamically typed whereas Java is statically typed.
  • Java is not simpler and compact to write test cases when compared to python.
  1.  Can you mention the challenges you face when handling the Ajax calls in Selenium Web driver?

The following are the challenges we face while handling the AJAX calls,

  • Pause command in Ajax calls is not conventional and reliable in handling. Long pauses do cause the test case execution increases the time of execution. We can use the waitForCondition instead to test the AJAX applications.
  • Assessing the risk associated with these applications is difficult.
  • Encoding and Serialization in the AJAX applications make it difficult in developing the automation test case scenarios.
  1. What are Break points and Start points in Selenium?
  • Break points:

The flow of execution is stopped using the break points. By doing this we can verify that the code is working in an expected manner or not.

  • Start points: 

The point from where the execution should begin is determined by the start points. When you want to run a test script from the middle of the code or a breakpoint, we use these.

  1. How is the desired capability useful in terms of Selenium?

A series of key-value pairs which can be used to store the information like the browser name, browser version, the path of the browser driver in the system etc., to determine the behaviour of the browser at the run-time. This feature or functionality is commonly referred to as desired capability.

For Selenium,

The driver instance can be configured using this.

It comes into practice when you want to run the test cases in different operating systems, browsers and versions.

  1.  When do you use AutoIT?

As we already know that Selenium is used only to automate web applications. But if we want to handle or manage or maintain the GUI, HTML pop-ups then, we need the use of AutoIT.

  1. Can you mention why do you need the Session handling in Selenium?

Session handling is very important while working with Selenium. This is because while working with the test case scenarios we need to establish the communication between the browser and the application while executing the commands. There can be an issue where while running a particular test script, another test script can be triggered with in the same host and same type of browser. This is the most important part and reason why we need the session handling.

  1.  Can you automate CAPTCHA?

The answer is No. We cannot automate CAPTCHA in Selenium. The concept of CAPTCHA is to ensure that the bots or automated test scripts should not have access to sensitive information, and that is why we cannot automate it. The captcha should be manually typed in-order to continue the flow of execution of the test suite.

  1. How do we launch different browsers in Selenium?
  • A driver instance should be created for a particular browser which we need to work upon. 
  • WebDriver driver = new FireFoxDriver();
  • WebDriver driver = new ChromeDriver();
  • Here, the WebDriver is the interface where the Firefox, chrome and all other browser driver implementations are made.
  1. Can you write a small code snippet to launch a Chrome browser in Web Driver?

public class ChromeBrowserLaunchDemo {  

public static void main(String[] args) {  

//Creating a driver object referencing WebDriver interface  

WebDriver driver;  

//Setting the webdriver.chrome.driver property to its executable’s location  

System.setProperty(“webdriver.chrome.driver”, “/lib/chromeDriver/chromedriver.exe”);  

//Instantiating driver object  

driver = newChromeDriver();  

//Using get() method to open a webpage  

driver.get(“http://javatpoint.com”);  

//Closing the browser  

Driver.quit();  

}  

}  

  1.  What is Locator and How do you locate an element in Selenium?

The elements of the web page are found and matched using locators to interact with. There are different kinds of locators to identify different types of elements on the web page. They are as follows,

  • ID
  • Name
  • Class
  • Partial Link
  • XPath
  • CSS Selector
  • Link Text
  1.  Which API is used for database testing in Selenium web driver?

JDBC (Java Database connectivity) is used for database testing in Selenium. This allows us to write the SQL (Structured Query Language) queries and execute them.

  1. Why do you choose Selenium over QTP (Quick Test Professional)?
FeatureSeleniumQuick Test Professional (QTP)
Browser CompatibilityAlmost all popular browsers are supported. Firefox, Chrome, Safari, Internet Explorer, Edge etc.,This supports only Chrome, FireFox and Internet explorer. Also, it supports only the Windows operating system.
DistributionDistributed as open-source and it is freely available.Distributed as a licensed tool and is commercialized.
Application Under Test (AUT)Web-based applications are only supported in this kind of automated testing.This provides support for both webs- based as well as the windows applications for automated testing.
Object RepositoryThe separate entity in Selenium is used to create the object repository.Automatic creation of the Object repository happens and is maintained too
Language SupportMultiple Programming languages like Java, Python, Perl, Ruby, C# etc., are supported by this Selenium.Only VBScript language is supported by this QTP.
Vendor SupportAs we already know that Selenium is a free tool, we do not get the vendor support in trouble-shooting the issues we face.Vendor support is guaranteed for the users using the QTP and they do get the quick responses as QTP is commercialized and licensed.

For a more detailed course, visit Great Learning Academy where you will find various courses on Machine Learning for free.

0

LEAVE A REPLY

Please enter your comment!
Please enter your name here

four × 4 =