Wednesday, April 10, 2024

Java Interview Questions For Selenium Tester

Don't Miss

What Are The Advantages Or Benefits Of Selenium Rc

Part7-Selenium with Java Tutorial | Practical Interview Questions and Answers | InputBox

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.

Most Popularly Asked Selenium Interview Questions And Answers

In this tutorial, we have listed the top 50 most commonly asked Selenium Interview questions including Selenium IDE, Selenium RC, Selenium Grid and Selenium WebDriver interview questions.

A quick note about this Selenium article series before we move to this tutorial:

This is the last tutorial in our Selenium online training series of 30+ comprehensive tutorials. I hope you all enjoyed these tutorials and started learning from it. If you are new here please head over to this very first tutorial in this training series.


Also, check out this The Best Online Selenium Training Course to learn Selenium automation tool from an expert having 10+ years of Selenium automation experience.


What Is Page Factory

Page Factory gives an optimized way to implement Page Object Model. When we say it is optimized, it refers to the fact that the memory utilization is very good and also the implementation is done in an object oriented manner.

Page Factory is used to initialize the elements of the Page Object or instantiate the Page Objects itself. Annotations for elements can also be created as the describing properties may not always be descriptive enough to differentiate one object from the other.

The concept of separating the Page Object Repository and Test Methods is followed here also. Instead of having to use FindElements, we use annotations like: @FindBy to find WebElement, and initElements method to initialize web elements from the Page Factory class.

@FindBy can accept tagName, partialLinkText, name, linkText, id, css, className & xpath as attributes.

Don’t Miss: What Kind Of Questions Should I Ask In An Interview

Why Selenium Rc Is Used

Selenium IDE does not directly support many functions like condition statements, Iteration, logging and reporting of test results, unexpected error handling and so on as IDE supports only HTML language. To handle such issues Selenium RC is used it supports the language like Perl, Ruby, Python, PHP using these languages we can write the program to achieve the IDE issues.

What Do You Mean By The Assertion In Selenium

Selenium Testing Interview Questions and Answers.

An assertion is a method of testing whether a particular condition is true or false. In Selenium, assertions are used to verify the state of elements on a page or the results of an action. Assertions can be used to check for the presence or absence of an element, the value of an element, or the text of an element. Assertions can also be used to check that an element is visible or hidden.

Assertions are an important part of testing with Selenium, as they enable you to verify that the state of your application meets your expectations. Without assertions, it would be difficult to know whether or not your tests are actually passing or failing.

Free Course: Programming Fundamentals

You May Like: What Is One Way Video Interview

Q28 What Is The Difference Between Sleep And Setsleep Method

Ans: Sleep and setSleep both methods are used to delay the speed of execution.

Thread.sleep : It is used to stop the current thread for the specified period of time. It’s done only once.

  • It takes a single argument in integer format.
  • For Example: thread.sleep- It will wait for 5 seconds.
  • It waits only once at the command given at sleep.

SetSpeed : It will stop the execution for every selenium command for specific amount of time.

  • It takes a single argument in integer format.
  • For Example: selenium.setSpeed- It will wait for 5 seconds.
  • It runs each command after setSpeed delay by the number of milliseconds mentioned in set Speed.

Core Java Interview Questions And Answers

1. What is a JVM?

JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

2. Does Java support multiple inheritance?

Java doesnt support multiple inheritance.

3. What is the most important feature of Java?

Java is a platform independent language.

4. What is difference between Path and Classpath?

Path and Classpath are operating system level environment variables. Path is used define where the system can find the executables files and classpath is used to specify the location .class files.

5. What are instance variables?

Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.

6. What is a pointer and does Java support pointers?

Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers.

7. What is the return type of the main method?

Main method doesnt return anything hence declared void.

8. What are local variables?

Local variables are those which are declared within a block of code like methods. Local variables should be initialized before accessing them.

9. Is Java a pure object oriented language?

Java uses primitive data types and hence is not a pure object oriented language.

10. Is JVM platform independent?
11. Can a main method be overloaded?


Not possible.

Also Check: Erp Interview Questions And Answers

Q25 What Is The Difference Between Implicit Wait And Explicit Wait In Selenium Webdriver

Ans: Implicit Wait: In Implicit wait, if WebDriver cannot find an element in the Document Object Model , it will wait for a defined amount of time for the element to appear in the DOM. The Implicit wait may slow down your tests, because once set, the implicit wait is set for the life of the WebDriver object’s instance.

An example of Implicit Wait:

  • driver.manage.timeouts.implicitlyWait

Explicit Wait:

Explicit waits are better than implicit wait. Unlike an implicit wait, you can write custom code or conditions for wait before proceeding further in the code.

An explicit wait can be used where synchronization is needed, for example the page is loaded but we are still waiting for a call to complete and an element to appear.

An example of Implicit Wait:

  • WebDriverWait wait = new WebDriverWait

What Is The Significance Of Testngxml

Automation Testing Mock Interview For 1-3 YOE (Java + Selenium +TestNG + Frameworks)

Im pretty sure you all know the importance of TestNG. Since Selenium does not support report generation and test case management, we use TestNG framework with Selenium. TestNG is much more advanced than , and it makes implementing annotations easy. That is the reason TestNG framewrok is used with Selenium WebDriver.

But have you wondered where to define the test suites and grouping of test classes in TestNG?

It is by taking instructions from the testng.xml file. We cannot define a test suite in testing source code, instead it is represented in an XML file, because suite is the feature of execution. The test suite, that I am talking about is basically a collection of test cases.

So for executing the test cases in a suite, i.e a group of test cases, you have to create a testng.xml file which contains the name of all the classes and methods that you want to execute as a part of that execution flow.

Other advantages of using testng.xml file are:

  • It allows execution of multiple test cases from multiple classes
  • It allows parallel execution
  • It allows execution of test cases in groups, where a single test can belong to multiple groups

You May Like: Java Programs Asked In Interview For Automation Tester

Ques64 How To Handle The Https Website In Selenium Or How To Accept The Ssl Untrusted Connection

Ans. Using profiles, we can handle accept the SSL untrusted connection certificate. Profiles are basically a set of user preferences stored in a file.

FirefoxProfile profile = new FirefoxProfile profile.setAcceptUntrustedCertificates  profile.setAssumeUntrustedCertificateIssuer WebDriver driver = new FirefoxDriver  

How To Switch To A New Window Which Opens Up After You Click On A Link

If you click on a link in a web page, then for changing the WebDrivers focus/ reference to the new window we need to use the switchTo command. Look at the below example to switch to a new window:driver.switchTo.window

Here, windowName is the name of the window you want to switch your reference to.

In case you do not know the name of the window, then you can use the driver.getWindowHandle command to get the name of all the windows that were initiated by the WebDriver. Note that it will not return the window names of browser windows which are not initiated by your WebDriver.

Once you have the name of the window, then you can use an enhanced for loop to switch to that window. Look at the piece of code below.

String handle= driver.getWindowHandle for ) 

Don’t Miss: How To Write A Email After An Interview

Top 40+ Java Interview Questions And Answers In 2022

In this post, we see Core Java Interview Questions for Freshers and Experienced. This post covers Core Java Interview Questions for Selenium Automation Testers too. This post on Java Interview Questions is prepared with basic and important concepts of Java with examples for your easy understanding.

Dont miss Java Quiz

How To Handle File Upload In Selenium

Selenium WebDriver question &  Answer

We can use three methods to perform file upload in Selenium:

  • sendKeys – We use the sendKeys method of keyboard events to upload the file easily. First, we identify the web element where the user should provide the file path, which is mostly a text input. Then through sendKeys we provide the path and click on the upload button. You can find an example here.
  • AutoIT tool – AutoIT is a third-party tool, which helps to automate the process of file upload. We need to create a .exe file that accepts the argument as upload filename. This script can be run on Windows only. You can find the contents of the AutoIT script here.
  • Robot class – It is used to automate alerts and pop-ups in Windows. An object of an instance of Robot class is created and with the help of keyboard events, the file is uploaded. You can find an example here.
  • You May Like: How To Reject An Interview

    Write A Code To Wait For A Particular Element To Be Visible On A Page Write A Code To Wait For An Alert To Appear

    We can write a code such that we specify the XPath of the web element that needs to be visible on the page and then ask the WebDriver to wait for a specified time. Look at the sample piece of code below:

    WebDriverWait wait=new WebDriverWait Element = wait.until)) 

    Similarly, we can write another piece of code asking the WebDriver to wait until an error appears like this:

    WebDriverWait wait=new WebDriverWait Element = wait.until) 

    Mention The Need For Session Handling While Working With Selenium

    While working with Selenium, we need session handling. This is because, during test execution, Selenium WebDriver has to interact with the browser all the time to execute the given commands. It is also possible that, before the current execution completes, someone else starts the execution of another script in the same machine and in the same type of browser. So, to avoid such a situation, we need session handling.

    Don’t Miss: Product Management Interview Case Study

    What Are The Essential Concepts Covered In This Selenium Course

    This Selenium Certification Course provides –

    • In-depth knowledge of concepts such as Java basics refresher, WebDriver, TestNG Framework, Web UI elements, Grid & Robot class, Selenium IDE, Automation frameworks, and more.
    • Case studies and projects in the domains of E-commerce, Test Automation Frameworks, and more.

    How To Read And Write A File In Selenium Webdriver

    Part32-Selenium with Java Tutorial | Practical Interview Questions and Answers | Database Testing

    The inclusion of data-driven testing is very important for a test automation framework. In order to read and write on Microsoft Excel sheets during test automation, we use a third-party Java library called Apache POI – Poor Obfuscation Implementation. And this library helps in reading and writing the .xls and .xlsx files through its methods.

    Code implementation to read and write excel file here.

    Also Check: What Are Some Questions You Get Asked At An Interview

    What Are The Significant Changes In Upgrades In Various Selenium Versions

    Selenium v1 included only three suite of tools: Selenium IDE, Selenium RC and Selenium Grid. Note that there was no WebDriver in Selenium v1. Selenium WebDriver was introduced in Selenium v2. With the onset of WebDriver, Selenium RC got deprecated and is not in use since. Older versions of RC is available in the market though, but support for RC is not available. Currently, Selenium v3 is in use, and it comprises of IDE, WebDriver and Grid. Selenium 4 is actually the latest version.

    IDE is used for recording and playback of tests, WebDriver is used for testing dynamic web applications via a programming interface and Grid is used for deploying tests in remote host machines.

    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,

    Multiple Programming languages like Java, Python, Perl, Ruby, C#, etc., are supported by this Selenium. Only VBScript language is supported by this QTP.
    Vendor Support As we already know that Selenium is a free tool, we do not get vendor support in troubleshooting the issues we face. Vendor support is guaranteed for the users using the QTP and they do get quick responses as QTP is commercialized and licensed.

    Don’t Miss: How To Watch Oprah Meghan Interview

    What Is The Use Of Javascriptexecutor

    JavaScriptExecutor is an interface which provides a mechanism to execute Javascript through the Selenium WebDriver. It provides executescript and executeAsyncScript methods, to run JavaScript in the context of the currently selected frame or window. An example of that is:

    JavascriptExecutor js =  driver  js.executeScript 

    How Will You Select A Date From A Datepicker In A Webpage Using Selenium For Automated Testing Explain With A Proper Code

    Top 100 Selenium Interview Questions &  Answers

    In such types of questions, the interviewer wants to assess how clear your understanding is about the framework. It is a good practice to explain the code while you write it so that the interviewer is engaged at all points and does not feel left out. We will be considering an example on MakeMyTrip.

    Here, we will be using the chrome browser and so we will be implementing the code for the chrome browser only. You can implement similar code for firefox and other browsers as well.

    First of all, we create a package named browserSelection which contains a class defined for handling different types of browsers such as chrome, firefox that we may want to use.

    package browserSelection import org.openqa.selenium.WebDriver import public class SelectBrowser  }

    Next, we create a package named datepicker which will contain a class containing methods defined for selecting a specific date on the website of MakeMyTrip. We need to import this package into our driver class and call the respective methods.

    In the above code, the function startBrowser is used to invoke the useChrome method from the imported package browserSelection. The function selectDateUtil is used to select the current date from the date picker of the sample web page. The endBrowser function is used to close the driver connections by invoking the quit method.

    Recommended Reading: How To Deny A Candidate After Interview

    Explain Dataproviders In Testng Using An Example Can I Call A Single Data Provider Method For Multiple Functions And Classes

    DataProvider is a TestNG feature, which enables us to write DataDriven tests. When we say, it supports DataDriven testing, then it becomes obvious that the same test method can run multiple times with different data-sets. DataProvider is in fact another way of passing parameters to the test method.

    @DataProvider marks a method as supplying data for a test method. The annotated method must return an Object where each Object can be assigned to parameter list of the test method.

    To use the DataProvider feature in your tests, you have to declare a method annotated by @DataProvider and then use the said method in the test method using the dataProvider attribute in the Test annotation.

    As far as the second part of the question is concerned, Yes, the same DataProvider can be used in multiple functions and classes by declaring DataProvider in separate class and then reusing it in multiple classes.

    How Can You Redirect Browsing From A Browser Through Some Proxy

    Selenium provides a PROXY class to redirect browsing from a proxy. Look at the example below:

    String PROXY = & ldquo rdquo org.openqa.selenium.Proxy proxy = proxy.setHTTPProxy .setFtpProxy .setSslProxyDesiredCapabilities cap = new DesiredCapabilities cap.setCapability WebDriver driver = new FirefoxDriver 

    Recommended Reading: What To Answer In Interview Questions

    Explain What Is The Difference Between Borland Silk And Selenium

    Silk Test Tool
    • Borland Silk test is not a free testing tool
    • Selenium is completely free test automation tool
    • Silk test supports only Internet Explorer and Firefox
    • Selenium supports many browsers like Internet Explorer, Firefox, Safari, Opera and so on
    • Silk test uses test scripting language
    • Selenium suite has the flexibility to use many languages like Java, Ruby,Perl and so on
    • Silk test can be used for client server applications
    • Selenium can be used for only web application

    Why Should Selenium Be Selected As A Testing Tool For Web Applications Or Systems

    Selenium with Java Interview Questions & Answers for Freshers & Experienced Part-1

    Selenium provides the following advantages, which make it an excellent automated testing framework:

    • It is free and open-source software with a large user base and supports providing community.
    • It has cross-browser compatibility and supports multiple browsers like Google Chrome, Mozilla Firefox, Internet Explorer, Edge, Opera, Safari, etc.
    • It supports multiple operating systems such as Windows, Linux, macOS, etc.
    • It facilitates the usage of multiple programming languages including Scala, Ruby, Python, PHP, Perl, Java, Groovy, C#, etc.
    • It provides support for distributed testing as well.

    Recommended Reading: How To Prepare For Virtual Interview

    More articles

    Popular Articles