Advanced
Data Structures Algorithms & System Design(HLD+LLD)
by Logicmojo

Cracking FAANG companies interviews with a few months of preparation

Learn Advanced Data Structures, Algorithms & System Design

Online live classes from 4 to 7 months programs

Get job assistance after course completion

Download Course Brochure

Back to home

Selenium Interview Questions

Selenium Interview Questions

Testing is an important part of the software development process (SDLC). Manual testing, in particular, entails physically running test cases against programmes in order to find
defects and errors. Manual testing, on the other hand, presented numerous obstacles, necessitating the development of a way to automate the testing process. Selenium,
a sophisticated automated testing tool, was born as a result. This is why landing a selenium-related job is a huge benefit, and knowing how to answer selenium interview
questions is crucial!



Learn More

So, let’s dive deep into the surplus of useful Selenium Interview Questions.

Selenium Interview Questions

What exactly is selenium?

Selenium is a free open-source framework for evaluating web applications across many browsers and platforms. Selenium Test Scripts can be created in a number of different programming languages, such as Java, C#, Python, and others. Testing carried out with the Selenium testing tool is referred to as Selenium Testing.

Selenium Software is a set of tools, each of which is tailored to the Selenium QA testing needs of a certain enterprise. The following is a list of Selenium's built-in tools:

Selenium Integrated Development Environment (IDE)
Selenium Remote Control (RC)
Selenium WebDriver
Selenium Grid

What is the SDLC process?

Testing is an essential component of the software development process (SDLC). There are two types of testing available.

Manual Testing

It entailed physically running test case scenarios against software in order to find flaws and problems.

This offered numerous obstacles as well as a significant amount of manual labour.

Automation Testing

Automation Testing, on the other hand, allowed us to automate testing operations while also increasing demand.

What does Selenium Suite imply, and what are its various components?

Selenium is a collection of testing tools that is often referred to as a Selenium Suite, with each tool designed to address a certain testing requirement.

Different components of Selenium Suite:

Selenium Integrated Development Environment (IDE): It's a Firefox/Chrome plug-in designed to make creating automation scripts easier by recording user actions in the web browser and exporting them as reusable scripts.

Selenium Remote Control (RC): It's a server that lets users create test scripts in the programming language of their choice. It takes commands from test scripts and sends them to the browser as Selenium core JavaScript commands, which the browser interprets.

Selenium WebDriver: It is a programming interface that assists in the creation and execution of test cases by communicating directly with the web browser and automating with its inherent compatibility. Unlike RC, it does not necessitate the use of a separate server to develop and run test cases.

Selenium Grid: By delivering commands to several workstations at the same time, it permits parallel execution of tests on different browsers and operating systems.

What are the drawbacks of using Selenium for testing?

Due to the fact that Selenium is an open-source tool, it does not have specialised tech support to help users with their issues.

Selenium only tests online apps; to test desktop and mobile applications, it must be combined with third-party tools such as Appium and TestNG.

Image testing has limited support.

Selenium lacks a built-in reporting and test management feature, necessitating integration with tools such as TestNG or JUnit, among others, in order to allow test reporting and management.

What is automation testing and what are the benefits of using it?

Test automation or manual testing Automation is the practise of automating the manual testing of an application or system by using testing tools that allow you to develop scripts that can be run repeatedly and generate detailed test reports for the application or system under test.

Advantages

It can be used to test an application or system's performance as well as its functionality.

It makes it easier to run test cases over and over again.

It enhances the system's accuracy and efficiency by decreasing the need for humans to manually develop test cases.

It aids in the testing of a big test matrix.

What's the difference between Selenium 3.0 and Selenium 2.0?

The Original Selenium project and the Web Driver project have merged to form Selenium 2.0. Although the Selenium RC has been deprecated, it is still used for backward compatibility.

Selenium 3.0, often known as an extension of Selenium 2.0, is naturally backward compatible and has various bug fixes, however it does not use the Selenium RC.

Is it possible to use Selenium to launch web browsers?

Yes, Selenium can launch web browsers such as Google Chrome, Mozilla Firefox, Internet Explorer, and others.

To use Selenium to launch web browsers, use the following commands:

WebDriver driver = new FirefoxDriver();

WebDriver driver = new ChromeDriver();

WebDriver driver = new InternetExplorerDriver();

What is selenese?

The Selenium command, often known as Selenese, is a series of selenium commands that run your test cases. For instance, the Selenium command open (URL) opens the supplied URL in the selected browser. A test script is the result of combining all of these commands.

Types of Selenese

Actions

Accessors

Assertions

What types of tests does Selenium support?

testing

Regression testing and functional testing are both supported by Selenium.

Regression testing: It is a full or partial re-execution of previously executed test cases to confirm that current functionalities are working properly.

Steps involved are:

Re-testing: All of the tests in the current test suite are run. It turns out to be both costly and time-consuming.

Regression Test Selecting: Feature tests, integration tests, and end-to-end tests are the three types of tests. Some of the tests are chosen in this step.

Prioritization of test cases: The priority of the selected test cases is determined by their business effect and important functionalities.

Functional testing entails comparing each of the application's functions to the needed specifications.

Steps are:

Identify test input
Compute test outcome
Execute test
Compare the test result to the actual result.

how many minimum parameters do selenium commands have?

Selenium has four parameters that must be passed. The following are their names:

Host

Instead of using a Local host on our local machine, we can bind Selenium to a specified IP address.

Port Number

To connect the Selenium tests to the Grid hub, we can also specify the port number, i.e. TCP/IP port. We must ensure that no other application with the same port number is running in any other location on the same computer.

Browser

The web browser in which the Selenium scripts must run.

URL

The test cases are triggered by the application URL.

In Selenium, what is the difference between the Assert and Verify statements?

Assert

We can see if an element is present on the page.

When a check fails, the test fails and the process is terminated. That's when the program's control flow comes to a halt.

Verify

It's solely used to indicate whether a condition is true or false.

This has no effect on the program's control flow.

Overall, the Verify statement does not pause the execution of the programme, whereas the Assert statement does.

What does an error test in Selenium mean?

A test that anticipates an exception to be thrown inside a test class is known as an exception test. It looks for a @Test annotation with the expected exception name in brackets.

In Selenium, an exception test for missing items is @Test(expectedException = NoSuchElementException.class).

What does XPath mean in Selenium? Explain the differences between XPath Absolute and XPath Relative?

XPath, commonly known as XML-Path (Extensible Markup Language Path), is a query language for XML documents that allows Selenium to locate elements by iterating through each element in a webpage. Data is saved in an XPath key-value pair format, similar to that of an HTML tag. It creates an absolute path for an element to be located on a webpage with a single slash, i.e.'/ ', and a relative path for an element to be located on a webpage with a double slash, i.e.'// '.

With correct examples, distinguish between findElement() and findElements() in the context of Selenium.

The following table compares and contrasts findElement() and findElements() in Selenium:

findElement()findElements()
Returns the first web element that matches the locator.It generates a list of all the web items that correspond to the locator.
A NoSuchElementException is thrown if no matching web elements are found.If no matching elements are found, an empty list is returned.
Syntax: WebElement button = webdriver.findElement(By.name("<(Name value)>"));Syntax: EList buttons = webdriver.findElements(By.name("<(Name value)>"));

Using findElements():

// JAVA
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class findElements {
  public static void main(String[] args) {
     System.setProperty("webdriver.chrome.driver", "C:\\Users\\vaibhav\\Desktop\\Java\\chromedriver.exe");
     WebDriver driver = new ChromeDriver();
     String url = "https://www.exampleurl.com/example.htm";
     driver.get(url);
     driver.manage().window().maximize();
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
     
     List<WebElement> rows = driver.findElements(By.xpath("//table/tbody/tr[2]/td")); // xpath with index appended to get the values from the row 1of table using findElements(), which returns a list
     System.out.println("The number of values in row 2 is "+ rows.size());
     driver.close();
  }
}

Using findElement()

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class findTagname {
  public static void main(String[] args) {
     System.setProperty("webdriver.chrome.driver",    "C:\\Users\\vaibhav\\Desktop\\Java\\chromedriver.exe");
     WebDriver driver = new ChromeDriver();
     String url = "https://www.exampleurl.com/example.htm";
     driver.get(url);
     driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
     driver.findElement(By.cssSelector("input[id='search']")).sendKeys("Selenium"); //Using id tagname attribute combination for css expression and get the element from findElement()
     driver.close();
  }
}

Explain the difference between driver.close() and driver.quit() used in selenium?

driver.close(): Closes the currently active window in which the user is working or the window that the web driver is currently accessing.

driver.quit(): Unlike the driver, you can issue commands. The close() command closes all of the program's windows, therefore it should be used with caution.

Both commands do not accept any parameters and do not return any results.

What is the same-origin policy and how is it implemented in Selenium?

Same Origin Policy is a security feature that allows a web browser to run scripts from one webpage to access the contents of another webpage if the origins of both pages are the same. The origin refers to the URL scheme, hostname, and port number combination. This policy was implemented to prevent unauthorised access to sensitive data on one webpage by another. Consider a Java programme used by scaler.com; it can access domain pages such as scaler.com/mentors and scaler.com/courses, but not pages from other domains such as facebook.com.

The Selenium Server (Selenium RC) is a client-configured HTTP proxy that "tricks" the browser into thinking Selenium Core and the web application under test are from the same source.

What is the wait? How many types of waits in selenium?

Waits are an integral part of the Selenium code that conducts a test case. It runs on scripts, which are commands that cause a page to load through it. Selenium Waits weakens and destabilises the pages. It offers a variety of wait possibilities that are adequate and appropriate in good situations. This ensures that you don't make any mistakes and wind up with unsuccessful scripts while automating your tests.

• Implicit Wait

• Explicit Wait

Explain Selenium Grid?

Selenium Grid is a Selenium Suite component that lets you run numerous tests in parallel across different browsers, operating systems, and machines. It's done by routing commands from remote browser instances through a hub server.

testing

Explain What is the difference between implicit, explicit, and fluent waiting?

Implicit wait:

For every subsequent web items, we can define a timeout for a particular length of time. Before raising the NoSuchElementException, the web driver searches for all web elements for the specified amount of time.

Explicit wait:

Before issuing the ElemntNotVisibleException, we can tell the Web Driver to wait for specific conditions to occur.

Fluent wait:

For the explicit wait, it's a minor extension. We can set the frequency with which we check the condition before throwing the ElementNotVisibleException in addition to waiting for particular requirements to be met.

Is Selenium capable of handling pop-up windows?

Selenium is an automation testing tool that can only function with web applications, as we well know. As a result, Selenium is unable to handle pop-up windows. We can, however, address this problem by integrating with third-party solutions.

How can you tell the difference between getwindowhandle() and getwindowhandles()?

getwindowhandles(): This returns the data type SetString> and is used to gather the addresses of all open browsers.

getwindowhandle(): This is used to get the address of the currently focused browser window and returns a String data type.

What are the different types of Selenium annotations?

Annotations are a type of syntactic metadata that can be introduced to Java source code. They can be used to variables, parameters, packages, and classes, among other things.
@Before, @Test, and @After are some of the Selenium commands.

What is POM? What are its advantages?

The Page Object Model design pattern is used to provide an Object Repository for web user interface elements. Each web page in the application must have its own page class. The page class is in charge of locating the WebElements in the page and then performing operations on them.

The following are some of the benefits of using POM:

Allows us to decouple UI operations and flows from verification, making the code more readable.

Multiple tests can use the same Object Repository because it is not dependent on Test Cases.

Code reusability

What is the difference between "/" and "//" in Xpath?

Single Slash "/": An Xpath with an absolute path is created with a single slash, i.e. the document node/start node will be the first node in the XPath.

Example: Absolute XPath: /html/body/div/div/form/input

The double slash is used to create an Xpath with a relative path, which means the selection can begin anywhere on the page.

Example: Relative XPath: //input[@id = 'email']

We can find an input with the id = 'email' anywhere in the document object model using this method (DOM).

What are the different navigation instructions that Selenium supports?

Selenium supports a total of four navigation instructions.

navigate().back()This command will take the user to the most recent webpage in their browser history.

navigate().forward()This command navigates the user to the next web page in the browser's history.

navigate().refresh()This command is used to refresh a webpage and reload its web components.

navigate().to()This command is used to open a new web browser and navigate to a specific URL. It accepts as a parameter the URL to be transferred to.

How do you know if anything is shown on the screen?

The user can use WebDriver to check the visibility of web elements. These site elements, which are utilised with the following techniques, can be buttons, radio buttons, drop, checkboxes, boxes, labels, and so on.

isDisplayed()
isSelected()
isEnabled()

How well do you grasp the concept of broken links? In Selenium, how do you identify broken links? Use code to adequately explain?

Broken links are links or URLs that cannot be reached. Due to a server issue, they may be inaccessible or unusable. The status of a URL is always 2xx, indicating that it is valid. There are a number of different HTTP status codes, each with its unique set of features. HTTP status 4xx and 5xx indicate that the request is invalid. Client-side problems are represented by the 4xx class of status codes, while server response errors are represented by the 5xx class.

Always verify your site for broken links to guarantee that the user does not get on an error page. The issue will occur if the rules aren't changed properly, or if the requested resources aren't available on the server. Because each web page may have a large number of connections and the process must be repeated for each page, manual link checking is a time-consuming activity.

Follow the steps below to identify broken links in Selenium.

Collect all of the links on a web page using the a> (anchor) tag.
Send an HTTP request for each link.
Check the HTTP response code to make sure it's right.
Rep for all of the links you captured in the first step.

package SeleniumPackage;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class BrokenLinks {
   
   public static void main(String[] args) {
       
       String pageURL = "http://www.interviewbit.com";
       String url = "";
       HttpURLConnection huc = null;
       int responseCode = 200;
       System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\selenium\\chromedriver_win32\\chromedriver.exe");
       ChromeOptions options = new ChromeOptions();
       options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors", "--silent");
       WebDriver driver = new ChromeDriver(options);//Creating an instance of the WebDriver class
       
       driver.manage().window().maximize();
       
       driver.get(pageURL);
       
       List<WebElement> links = driver.findElements(By.tagName("a")); // getting hold of all the elements having the anchor tag
       
       Iterator<WebElement> it = links.iterator();
       // Iterating over the obtained list of elements and checking them one by one
       while(it.hasNext()){
           
           url = it.next().getAttribute("href");
           
           System.out.println(url);
       
           if(url == null || url.isEmpty()){
               System.out.println("The linked element has invalid href url.");
               continue;
           }
           
           if(!url.startsWith(pageURL)){
               System.out.println("URL belongs to another domain, skipping it.");
               continue;
           }
           
           try {
               huc = (HttpURLConnection)(new URL(url).openConnection());
               
               huc.setRequestMethod("HEAD");
               
               huc.connect(); // connecting to the url
               
               responseCode = huc.getResponseCode(); // reading the response code on firing the url
               
               if(responseCode >= 400){
                   System.out.println(url+" is a broken link");
               }
               else{
                   System.out.println(url+" is a valid link");
               }
                   
           } catch (MalformedURLException e) {
               e.printStackTrace();
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
       
       driver.quit();
   }
}

We first set up the system properties and then initialise a webdriver object in the code above. With the help of the findElements() method, we can locate all the elements on the web page that have the anchor tag. Then we go through each item on the list one by one, opening the URL and reading the response code to see if it's a broken link.

🚀Conclusion

This page has now come to a close. You should be able to construct your own programmes using the material on this page and some practise, and little projects are highly encouraged for improving your programming skills. It's difficult to learn all there is to know about programming in only one course. Programming is a never-ending learning process, whether you're a seasoned professional developer or a total rookie.

TEST YOUR KNOWLEDGE!



1. Which of the following two instructions should you use to validate that a button has shown on a page?




2. What does assertTitle look for?




3. Choose a language that the Selenium RC does not support.





4. Which of the following is true about the Action commands in the context of Selenium?



5. Which selenium command checks if a certain piece of text is present on the page?



6. Which is not the case in Selenium with Globs?



7. Which of the following java based build tools might be needed for selenium grid?



8. In Selenium, which of the following is not a wait command?






logicmojoContact

HAVE A QUESTION? GIVE US A CALL OR CONTACT US - WE'D LOVE TO HEAR FROM YOU

PHONE: +91 80889-75867

WhatsApp : Click Here...

FEEDBACKFORM