71+ UnAnswered Critical Selenium interview questions

In this tutorial of selenium interview questions, we will cover all the critical Selenium interview questions questions along with advanced Selenium Automation framework interview questions .This tutorial is divided into three segments :

Selenium Framework Interview Questions

Advance selenium interview questions

Intermediate selenium interview questions

NOTE : The focus of this Selenium interview Questions and Answers tutorial is to discuss most critical and complex questionnaire as you might already be aware of the basic questionnaires on .

Initially we will start with Advance Selenium Framework interview questions and answers and then move forward Critical/Advanced selenium interview questions and answers and then lastly we finish this tutorial with intermediate levels so that you can prepare well.

Selenium Interview Questions
Selenium Interview Questions

Selenium Framework Interview Questions

Advance Selenium Interview Questions

Intermediate selenium interview questions

Selenium Framework Interview Questions : 

How many popular types of Selenium framework are there?

There are four different types of Selenium framework are there, which are : 

  • Page Object Model framework 
  • Hybrid Page Object model Framework 
  • Data driven framework 
  • Keyword Driven framework 
  • BDD framework 

How many different approaches are there to design the Page Object Model framework?

  • Classic Page Object Model with Page Factory  
  • Customized Page object Model without Page factory 

What is Page factory in selenium ?

PageFactory is a class from Selenium library from a package called as org.openqa.selenium.support which helps to design the Page Object Design pattern in the Page Object Model framework, which has few implementations such as :

  • initElements() method basically a static method in Page Factory Class, through with all the locators elements can be initialized.
  • We need to use @findBy annotation to declare the Webelement by different locator strategies (i.e., XPath, name, id, CSS, etc.)
  • The Page Factory class has a constructor as public PageFactory()

What is the key design difference between Classic Page Object Model and Customized Page Object Model?

  • a. In the Classic Page Object Model, we use Page Factory to build the Page Object Model by keeping the All the Page locators(WebElements) in the Pagefactory class by using @findBy annotation and initElements() method.
  • In the Customized Page Object Model, we design the different interfaces to store the locators for different Pages for the Web. and also, unlike the Classic Page Object Model here, we have separate classes for defining different methods for different Page functionalities and assertions for separate webpage functionalities.

So each webpage should have one interface to store locators and 1 class for the page level web operations and their respect assertions.

What is the design principle of the Page Object Model Framework?

The Design principle of the Page Object Model framework is based on principles or concepts, which are : 

  • The whole WebApplication is divided into different web pages, and each of the webpages represents a separate java/c#(respective languages on which the framework is built-in) class representing the functionalities for the respective webpages.

So, All the page actions(different operations of the web page functionality)reside on the respective Page classes.

  • The respective page’s locators are kept in separate interfaces or in the Page factory classes.

Mention the key differences among Page Object Model and the Hybrid Page Object Model?

The difference between Page Object Model and Hybrid Page Object Model is that the Hybrid Page Object Model is based on Page Object Model framework Design along with the extensive features of the Data-Driven Framework and supports a wide variety of the Data Operations Utilities such as below : 

  • Excel Data utils
  • Properties Data utils
  • Yaml Data Utils
  • TestNg Data Providers Utils
  • DataBase Utils
  • PDF Data Utils
  • Image Data Utils
  • CSV Data Utils

What is the language Parser used in the Cucumber -BDD framework?

The language parser used in the Cucumber -BDD framework is Gherkin.

What is the Gherkin language?

Gherkin is DSL (Domain Specific Language) and English like language, which is very much readable and understandable (i.e., give(), when(),then(), etc.)

What do you mean by given() in Gherkin?

 Given () method states that some situation or scenario is given or stated.

 What do you mean by when() in Gherkin?

When () means when you perform some operations.

What do you mean by then() in Gherkin?

then() is used as assertions after the operations are performed by given().when() .

What CI tool do you use as part of the framework?

We use Jenkins (majorly) as an open-source CI tool.

What build tool do you use as part of the framework?

We use build tools such as Maven/Gradle/ant (it was previously used).

What is the key difference between maven and Gradle?

Gradle is the advanced version of what maven perform, and along with that, we can create tasks as well (like the feature that was available in ANT ), so we can consider on a high level : 

Gradle =>> Maven +Ant 

As part of Selenium C#, we use Gallio as a build tool. 

What’s the Unit Test framework that we use as part of the Selenium Automation framework?

We majorly use TestNG/JUnit(JUnit is less used nowadays) as part of the unit test framework while building the Automation framework with Selenium. 

As part of the Selenium C# framework, We use NUnit/MbUnit as a unit test framework.

What approach can be taken into consideration while designing the Reporting tools as part of the Selenium framework?

There is various reporting approach we could take while designing the framework :

  • TestNg report.
  • Xslt report.
  • Allure Report.
  • extent report

Apart from these open-source reporting tools integration, we can also opt for some advanced reporting features or dashboard to build with the below technologies and tools :

  • ELK stack, i.e., Elastic search, Logstash, and Kibana, which is very, very advance and robust in nature and being in use and Advanced Automation framework development.
  • Customized HTML reporting .

How do you use ELK to build the reporting dashboard with Selenium Framework :

There is a basic base design principle which is being used to design the Automation dashboard, which are : 

  • Use TestNg listener and integrate it to ElasticSearch indexes for any events like pass, fail, skipped, etc. 
  • Create different indexes (pass fail and what all attributes you need for reporting like exceptions and their details etc.).
  • Use those indexes to display the Data to the Kibana Dashboard. 

How do you build an HTML customized report?

You can make use of different listeners and reporters interfaces provided by TestNg to record the events and their respective data sets and create HTML by using those data sets and the HTML tags in the report utils.

What are the challenges that you have faced while developing a framework?

There are different challenges you can mention as per your experience gives while developing the framework, for example : 

  • What language design pattern to choose from to start to build the design of the Automation framework (e.g., Factory Design Pattern, Singleton Design Pattern, Abstract Design Pattern, etc.)
  • How to handle different types of WebDrivers (such as Local Driver, RemoteDriver, EventDriver) instances and whether to keep driver instances as static or no static, etc and what are their respective approaches.
  • Integration with different third party tools such as Image verification, Native App-based operations(e.g., a window pop up, etc.), TestCase Management tool integration such as JIRA, TestLink, etc. 
  • Advance reporting features.
  • How to build critical features utilities like (few examples such as Zoom in /Zoom out, Image Text validation, PDF validations or handling different issues with certificates, advance TestNG listener implementations, advance exception handling, and reporting, etc.) 

Mention which all Selenium components you have used in your Selenium Framework?

  • Selenium WebDriver
  • Selenium GRID 

You can mention depending on your framework.

What is the flow of your Automation framework?

You can mention the flow of execution of your framework depending on your Framework flow and the tools that you have used; below is an example you can mention :

CI(Jenkins) → Build Tools (Maven/Gradle) → Unit Test Framework (TestNg) → TestNg.xml ->> TestClasses → BaseTest(Every Test Class extends Base class as baseTest where the @beforeClass /@BeforeSuite @afterClass etc exits )–>TestMethods → PageClasses→ Page Methods→ WebUtilities(reusable class for the WebAction utilities )–>> Reporting Utils 

What do you understand by Data-Driven framework, and where do we use a Data driven framework?

A Data-Driven framework is basically a framework that is driven by Data. Having said that, in which the application or the type of the application where the Same Test cases or scenarios is executed several times with the different data sets or the source or Data is very vast like in the case where we need to interact a variety of Data sources there we use Data-driven framework. 

The different Data Source can be : 

  • A. Excel Data utils
  • B. Properties Data utils
  • C. Yaml Data Utils
  • D. TestNg Data Providers Utils
  • E. DataBase Utils
  • F. PDF Data Utils
  • G. Image Data Utils
  • H. CSV Data Utils

How to explain the selenium automation framework in an interview?

 There are different approaches you can take to explain the selenium automation framework in an interview; the best possible approach could be the modular approach, which is to break down the explanation into different separate modules, such as :

  • Type of the Framework and Key and unique features of the Framework.
  • Tools and Technologies used in Selenium framework.
  • The flow of the execution of the Selenium Framework.
  • Different Critical Scenarios handled by your framework.

Let’s Discuss in Detail : 

Type of the Framework and Key and unique features of the Framework :

You need to mention the type of the framework such as Hybrid Framework, page object model framework, hybrid Page Object Model framework, etc. 

You need to mention the unique features of the framework, such as for example :

  •  Advance real-time Reporting with different Tools such as ELK stack or customized HTML reporting feature/Allure reporting/extent report.
  • Advance logging and debugging framework or tool such as Graylog.
  • Image recognition or image Data extraction or validation with tesseract OCR technologies
  • Integration with multiple third-party tools such as TestCase management tool TestLink/JIRA etc., AutoIT/Sikuli for different Native application interaction with Selenium framework.
  • Implementation of different advanced TestNg listeners /reporters for advanced features such as test triggering of the failed tests, manipulation of the TestNG Annotation in the runtime with IAnnotationTransformer, etc.

Tools and Technologies used in Selenium framework :

You can mention the tools and technologies used while developing the framework, such as :

  • Jenkins
  • Maven
  • TestNG
  • Java as a language
  • Sikuli/AutoIT
  • Tesseract OCR 
  • ELK stack
  • Graylog

The flow of the execution of the Selenium Framework :

You can mention the flow of the framework execution, i.e., how do you trigger the test suites and how it flows to the test cases/methods and till the Framework Utils such as webutils, data utils, etc. You can refer to the above question where we discussed how to explain the flow of the execution of the Selenium framework.

Different Critical Scenarios handled by your framework :

In this module, you can discuss the critical features that have been automated as part of your application automation with your framework. There can many use cases or features that you can mention here, such as : 

  • ImageData validation .
  • Automating TestCases via TestCase Management tool.
  • Parallel execution exhaustively in different browsers and multiple sessions from each browser to reduce the execution time.
  • Window Based integration and automating such use cases etc.

How to design logging scenarios in the Selenium framework?

You can use log4j for logging, or you can use real-time logging and debugging dashboard implementation with Graylog, which basically uses ElasticSearch in the backend for real-time logging and debugging details.

What are the design patterns you have used while designing the framework?

You can use different Design patterns as per the need and design of the Automation framework, such as :

  • Factory Design Pattern for Driver browser implementation for multiple browsers(Chrome, IE, Firefox, etc.)with different drivers such as local driver, remote driver, event driver, etc.
  • Abstract Factory design pattern.
  • SingleTon design Pattern for configurator (properties data load or Yaml Data load)for the configuration related data.

Critical or Advance Selenium Interview Questions :

How many ways can you run your automation script parallelly?

There are multiple ways and approaches through which you can run your test scripts parallelly, such as : 

  • With TestNG through testng.xml and using parallel and thread-count parameters.
  • With build tools such as Maven/Gradle build tool in the below approach: 

Maven :

Using surefire plugin : 

<forkCount>5</forkCount>

 <reuseForks>true</reuseForks>

Here fork count represents the number of parallel threads count.

Gradle : 

tasks.withType(Test) {
        maxParallelForks = Runtime.runtime.availableProcessors()
    }

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

setSpeed() method in Selenium basically sets the speed of the execution of each and every action/command. 

So let’s say if you setSpeed(“2000”), then every line of execution will be delayed by 2000 milliseconds. 

On the other hand, Thread.sleep() will introduce a 3000 milliseconds delay (it will suspend the thread for the specific operation ). 

Hence sleep() is applied to 1 operation; on the other hand, setSpeed() introduces the delay for each and every operation and thus setting the speed of the execution.  

How to verify the presence of a ScrollBar with Selenium? 

To verify horizontal scroll bar in webpage with Selenium, we use Javascriptexecutor in the below manner : 

JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
Boolean presenceOfHorizontalScroll = (Boolean) javascriptExecutor.executeScript("return document.documentElement.scrollWidth>document.documentElement.clientWidth;");

To verify the vertical scroll bar in WebPage using Selenium webdriver also we need to use Javascriptexecutor : 

JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
Boolean presenceOfVerticalScroll  = (Boolean) javascriptExecutor.executeScript("return document.documentElement.scrollHeight>document.documentElement.clientHeight;");

Write the code to handle any hidden Web elements in selenium webdriver?

WebElement element=driver.findElement(By.id("id_of_Element"));
JavascriptExecutor jsExecutor = (JavascriptExecutor)driver;
jsExecutor.executeScript("arguments[0].click();", element);

Mention different approaches to handle a window based pop up using Selenium webdriver?

You can use the below approaches to handle Window based application such as window Pop up : 

  • With Robot Class 
  • With Keys class in Selenium
  • With the integration of Sikuli
  • With the integration of AutoIt and Jacob(Java com Bridge) 

What is the parent interface of WebDriver?

SearchContext

Mention the key differences between POI and JXL Jars?

POI supports Conditional formatting, rich text formatting, or xlsx format, but on the other hand, JXL does not support any of these features.

POI library is maintained and updated compared to JXL.

How do you handle your network latencies using Selenium?

We can use the following to handle network latency using in Selenium : 

Driver.manage.pageloadingtime

What are the approaches you would take to handle Ajax content testing with Selenium WebDriver?

AJAX is basically Asynchronous Javascript And XML. All the communication of the AJAX-based Application is based on asynchronous calls, 

which allow any event to be performed without refreshing the webpage. Each operation can be performed independently from other Events.

What are the challenges while working with AJAX calls in Selenium WebDriver?

  • A. In AJAX, the DOM page partial code is generated/modified after an action, while the DOMM page remains the same.
  • B. It’s not easy to perform well-defined assertions on AJAX applications.
  • C. You have to continuously keep on listening to the events till the time is expired, and take action based on that, and sometimes 
  • it becomes sporadic in nature.
  • D. Prolonged wait time makes the scripts and browser slow, and at times the browser can become dead.

To work with the AJAX application, you may need to use waits for the above-mentioned use cases : 

  • Implicit Wait
  • Explicit Wait 
  • Fluent Wait 
  • SetSpeed
  • Thread.sleep
  • WebDriverWait

What’s the approach to work with Proxy in Selenium Webdriver?

There are two different Approaches you can handle proxy in Selenium Webdriver : 

  • Pass the Proxy setting in desired Capabilities while spinning the browser instances.
  • By manually setting the Browser proxy 
Proxy proxy=new Proxy();
proxy.setHttpProxy("localhost:8889");
DesiredCapabilities capabilities=new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver=new FirefoxDriver(capabilities);

Mention the ways to achieve synchronization in WebDriver?

We can handle synchronization in Selenium webdriver by using different wait mechanism : 

  • implicitWait
  • ExplicitWait with different expected conditions.
  • FluentWait

Mention the key differences between TestNg @BeforeTest and @BeforeMethod ? 

In TestNg @BeforeTest and @BeoreMethod has different aspects, are:

  • @beforeMethod: this block of code, i.e., the method with this annotation, gets executed once before each and every @test method of TestNG
  • @beforetest: Method with this annotation gets executed once before each and every testTag of TestNG.xml.

List the different types of WebDriver APIs present in Selenium?

  • Chrome Driver
  • Firefox Driver
  • Gecko Driver
  • InternetExplorer Driver
  • Safari Driver
  • Opera Driver
  • htmlunit Driver
  • PhantomJSDriver
  • Android Driver
  • iPhone Driver
  • EventFiringWebDriver

How many ways you can achieve headless execution with Selenium?

We can use the below drivers to achieve headless automation with Selenium: 

  • PhantomJSDriver
  • htmlunit Driver

What is Fluent Wait In Selenium WebDriver?

With FluentWait, you can set a maximum amount of time(let’s say 3 minutes ) to wait to meet a specific condition, and during that time, you will continuously poll or check with a certain frequency (very small unit of time, let’s say 3 secs )to check.

If the condition is met, then it will return true, and if not, it will throw an “ElementNotVisibleException” exception.

The syntax of fluentwait in Selenium is :

Wait fluentWait = new FluentWait(driver).withTimeout(100, TimeUnit.SECONDS)
  .pollingevery(2, TimeUnit.SECONDS)
  .ignoring(ElementNotVisibleException.class);

Tell us some Selenium exceptions that you have encountered while working with` Selenium WebDriver?

  • WebDriverException
  • NoSuchElementException
  • StaleElementReferenceException
  • TimeoutException
  • NoAlertPresentException
  • NoSuchWindowException
  • IllegalStateException

How do you delete cookies in Selenium?

The command to delete the cookies in Selenium is : 

driver.manage().deleteAllCookies();

Explain the approach that how do you read the javascript variable in selenium webdriver?

We need to use JavascriptExecutor to be able to do so. 

JavascriptExecutor jsExecutor = (JavascriptExecutor) webdriver;
String jsVariable = (String.valueOf(jsExecutor.executeScript("return document.title")));

How To Perform Zoom In And Zoom Out Browser operation In Selenium?

We can perform zoom in and zoom out operation in Selenium by using two different approaches, such as : 

  • Robot class in selenium
  • Keys class in Selenium 

Zoom in using Robot class in selenium

Robot robotInstance = new Robot();
//Zoom in

robotInstance.keyPress(KeyEvent.VK_CONTROL);
robotInstance.keyPress(KeyEvent.VK_ADD);
robotInstance.keyRelease(KeyEvent.VK_ADD);
robotInstance.keyRelease(KeyEvent.VK_CONTROL);

Zoom out using Robot class in selenium


Robot robotInstance = new Robot();
robotInstance.keyPress(KeyEvent.VK_CONTROL);
robotInstance.keyPress(KeyEvent.VK_SUBTRACT);
robotInstance.keyRelease(KeyEvent.VK_SUBTRACT);
robotInstance.keyRelease(KeyEvent.VK_CONTROL);

Zoom in using Keys class in selenium

driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL,Keys.ADD));

Zoom out using Robot class in selenium

driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL,Keys.SUBTRACT));

How to clear a field in selenium without using a clear() method?

We can clear any field without using the clear() method in the below approach : 

We can use the Keys class in Selenium to achieve the same : 

WebElement element = driver.findElement(By.id("id_of_Element"));
element.sendKeys(Keys.chord(Keys.CONTROL, "a"));
element.sendKeys(Keys.DELETE);

How to rerun the failed test cases in selenium?

We can rerun the failed test cases in Selenium in the below two approaches :

With auto-generated TestNG-failed.xml :

After the test execution (ran from testng.xml), TestNG automatically generates TestNG-failed.xml; you can rerun the same XML to run the failed tests ONLY.

By implementing IRetryAnalyzer interface from testNg :

By implementing the interface IRetryAnalyzer we can automatically rerun the failed test cases with TestNg :


If you implement the IRetryAnalyzer you can auto rerun  failed test with TestNg :

public class Retry implements IRetryAnalyzer {
   int counter = 1;
   int retryMaxLimit = 3;
   public boolean retry(ITestResult result) {
       if (counter < retryMaxLimit) {
           counter++;
           return true;
       }
       return false;
   }
}

How to Highlight Element in Selenium WebDriver?

We can use JavascriptExecutor to set the color of the Webelement by mentioning the element.


WebElement element = driver.findElement(By.xpath("id_of_the_element"));
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("arguments[0].setAttribute('style', 'background: red; border: 2px solid red;');", element);

How to double click in selenium?

We can use the Actions class in Selenium to perform the DoubleClick operations in the below manner. The below method takes an argument on which you have to perform DoubleClick.

public void doubleClick(By locator) {
		try {
			WebElement element = driver.findElement(locator);
			Actions actions = new Actions(driver).doubleClick(element);
			BASE_LOGGER.info("Performed the double Click on the Element  : " + locator);
		} catch (StaleElementReferenceException e) {
			BASE_LOGGER.error("Element is not attached to the page document " + e.getCause().getMessage());
		} catch (NoSuchElementException e) {
			BASE_LOGGER.error("Element " + locator + " was not found in DOM " + e.getCause().getMessage());
		} catch (Exception e) {
			BASE_LOGGER.error("Element " + locator + " was not clickable " + e.getCause().getMessage());
		}
	}

How to scroll in selenium?

We need to use Javascript to perform the scrolling, and the below method provides an advanced approach to scroll into element till the element is visible, which is scroll into view : 

public void scrollIntoView(By locator) {

  try {
     JavascriptExecutor executor = (JavascriptExecutor) driver;
     WebElement element = driver.findElement(locator);
     executor.executeScript("arguments[0].scrollIntoView(true);", element);
     BASE_LOGGER
           .info("scrollIntoView operation has been performed for the locator : " + String.valueOf(element));
  } catch (Exception e) {
     String exceptionData = e.getCause().getMessage();
     BASE_LOGGER.error("Error encountered i.e : " + exceptionData
           + " while performing scrollIntoView on the element : " + locator);

  }

}

How to get all links on the page in selenium?

We can use By.tagName(“a”) to fetch all the links that are available on the page as link refers to the tag called as a; the method goes in the below manner : 

public List<WebElement> getAllLinks() {

  try {
     List<WebElement> allLinks = driver.findElements(By.tagName("a"));
     int numberOfLinks = allLinks.size();
     BASE_LOGGER.info("Number of Links in the Current Page is : " + numberOfLinks);
     BASE_LOGGER.info("GetAllLinks operation has been performed for the Current Page : ");
     return allLinks;
  } catch (Exception e) {
     String exceptionData = e.getCause().getMessage();
     BASE_LOGGER.error("Error encountered i.e : " + exceptionData
           + " while performing GetAllLinks for the Current Page :");
     return null;
  }

}

How to find the number of iframes on a page in Selenium?

We can use the below method to find the number of iframes in a page in Selenium :

public int numberOfIframesInPage() {
  try {
     JavascriptExecutor exe = (JavascriptExecutor) driver;
     Integer numberOfIFrames = Integer.parseInt(exe.executeScript("return window.length").toString());
     BASE_LOGGER.info("Number of IFrames in the current Window are : " + numberOfIFrames);
     return numberOfIFrames;

  } catch (Exception e) {
     BASE_LOGGER
           .error("Exception occurred in Finding numberOfIframesInPage with : " + e.getCause().getMessage());
     return 0;
  }

}

How to switch to default frame in selenium webdriver?

We can use switchTo().defaultContent() method to switch to default frame in Selenium Webdriver: 

public void switchToDefaultFrame() {
  try {
     driver.switchTo().defaultContent();
     BASE_LOGGER.info("Switched to Default Content ");
  } catch (Exception e) {
     BASE_LOGGER.error("Exception Occurred while switching to default Content ");
  }
}

How to handle tabs in selenium?

We can use a List to store all the tabs available and use driver.getWindowHandles() to store the tabs, and once after this, we can handle tabs one by one in the below approach, such as : 

public void switchToTab(int indexOfTab) {

  try {

     ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
     driver.switchTo().window(tabs.get(indexOfTab));
     BASE_LOGGER.info("Successfully switched to tab with tab index as : " + indexOfTab);
  } catch (Exception e) {
     String exceptionData = e.getCause().getMessage();
     BASE_LOGGER.error(
           "Unable to Switch to Tab for :" + indexOfTab + " i.e failed with exception as : " + exceptionData);

  }



}

Intermediate selenium interview questions

Is WebDriver a class or an interface?

Webdriver is an interface where all the driver classes such as ChromeDriver, FirefoxDriver create an object and have reference to the Webdriver interface’s reference.

Which one is faster, XPath, or CSS?

CSS is faster than XPath. 

Why CSS is faster than XPath?

Every browser engine is different, and hence parsing strategy and engine implementation are different through the written XPath. That is why parsing XPath becomes inconsistent at times; for example, IE does not have its own engine implementation to parse XPATH; hence Selenium injects its own native XPath engine to parse XPATH in IE. 

What is heightened privileged browsers?

When the browsers are opened up with some predefined settings (instance with special privileged mode )such as with certain Profiles or Certificates, then it’s called heightened privileged browsers sessions. 

We can launch a browser with Selenium with Profiling or set certificates for the same purposes.

What is headless browser Selenium and how we perform headless browser testing?

  A headless browser is a simulation program for the browser where we don’t have a UI, but we still can run Application under test in invisible mode 

 and perform the desired web operation in the background.

 We use HeadLess browser drivers such as HTMLUNIT driver or phantomJS Driver to perform headless browser testing.

Selenium vs. puppeteer ? 

There are several differences between Selenium and puppeteer (which is a new tool compared to Selenium and developed by Google Chrome DEV)

We will discuss here the comparison between Selenium VS Puppeteer in different aspects : 

  • Installation: puppeteer is easy to install compared to Selenium.
  • Puppeteer supports only Chrome as of now; Selenium supports a wide range of browsers.
  • Native Language for puppeteer is Node JS; on the other hand, Selenium supports multiple languages.
  • Puppeteer is faster than Selenium.
  • puppeteer is Developed and maintained by Google Chrome Dev, and on the other hand, Selenium has huge open source community support

HardAssert vs SoftAssert ?

Both the assertion approaches are from TestNg, and each of them has its respective pros and cons

  • After the HardAssert statement, the execution stops (if the assertion fails), and the remaining portion of the TestScript gets skipped.On the other hand, by using the Soft Assert, we can continue with the remainder of test scripts even though any assertion failure happens in the meanwhile.  
  • Once the Hard assertion fails, it reports immediate failures of the script, but for soft assert, it keeps track of all the assertion failures (if in case any ) within the test script, and at the end, it reports all the failures together.
  • Soft assert is always safe to use, and you can test your script all the way through from starting till the end and take a look at all the failures together and resolve it.

 When you are under the circumstances where you need to have an assertion that’s obvious, i.e., without that step, the remaining steps of the script do not make sense to be executed, then you can put Hard Assert there.

 How to set the window size in selenium?

We can create an object of Dimension class and pass that object to setSize() method : 

Dimension dimension = new Dimension(480,700);
driver.manage().window().setSize(dimension);

What is the version control system you use while working with Selenium?

You can mention whatever VCS you use, such as Github, SVN, etc.

How to clone a git repo?

We can clone the git repo by using :

Git clone repo

How to pull the Git repo code?

Git pull remoteRepoURL branchName

How to push the code to git repo?

Git push remoteURL branchName

How to set the Remote? 

git remote add ProvideARemoteName remoetURL

How to verify the available remotes?

Git remote -v 

How to check which remote URL you currently are in? 

git config --get remote.origin.url

How can you integrate your framework with Jenkins?

As part of the Selenium Automation framework, we are using build tools(such as Maven/Gradle), and we can create a Jenkins Job and connect the Maven/Gradle by providing the configuration with VCS (i.e., Github, etc.)

What are the disadvantages of Sikuli?

  • At times Sikuli acts sporadically and is not stable and reliable all the time; let’s say we need to perform some actions on some images, and we are running a parallel test script, then one of the scripts gets failed because, in parallel execution, one image gets overlapped with another image so the operation on one of the images could not be performed.
  • Sikuli makes your Selenium script slower, as integration with any third-party tools makes the Selenium Automation slower in nature.
  • Siklu performs operations based on images and their locations, so if those locations get changed, then you will see failure in your test script; hence it’s not that consistent.

How to perform database testing using selenium?

We can perform database testing using selenium in the below modular approach : 

  • Selenium Database connection with Java JDBC. 
  • Create a DB statement . 
  • Use the statement to execute a SQL query and return the data. 
  • Closing the Database Connection.

Here is below code snippet for the above steps : 

Selenium Database connection Setup with JAVA JDBC and creates a DB statement : 

   static Connection connection = null;
   private static Statement statement;
   public static String DataBase_URL = "DB_URL";
   public static String DataBase_USER = "DB_UserName";
   public static String DataBase_PASSWORD = "DB_password";



   /* This method Creates the connection with Java JDBC and return it to the Test method to use along with statement 
   */
@BeforeTest
   public void setUp() throws Exception {
       try{

           String dbClass = "com.mysql.cj.jdbc.Driver";
           Class.forName(dbClass).newInstance();
           Connection con = DriverManager.getConnection(DataBase_URL, DataBase_USER, DataBase_PASSWORD);
           statement = con.createStatement();
       }
       catch (Exception e)
       {
           e.getCause().getMessage().toString();

       }


   }

Use the statement to query the DB with SQL : 

@Test
public void test() {
   try{
       String queryData = "select * from TableName";

       ResultSet res = statement.executeQuery(queryData);
       while (res.next())
       {
           System.out.print(res.getString(1));
           System.out.print(" " + res.getString(2));
       }
   }
   catch(Exception e)
   {
       e.getMessage();
   }
}

Closing the Data Connection : 

This step is very important; otherwise, we may end up creating multiple database connections without closing them after the usage, which may cause several issues. 

Here is the code snippet for the same : 

@AfterTest
public void tearDown() throws Exception {

   if (connection != null) {
       connection.close();
   }
}

How to verify the background color and color of a WebElement using Selenium? 

We need to use a method called getCssValue(“color”) for retrieving the colour of a webelement and getCssValue(“background-color”) to pull the background colour of a webelement.

Here is the code snippet : 

String colour  = driver.findElement(By.xpath("XPATH_of_the_Element")).getCssValue("color");

String backgroundColour = driver.findElement(By.xpath("XPATH_of_the_Element")).getCssValue("background-color");

How to verify the font-size of a WebElement using Selenium webdriver? 

We can use the the method called getCssValue(“font-size”)

String fontSize  = driver.findElement(By.xpath("XPATH_of_the_Element")).getCssValue("font-size");

How to verify the font type of a webelement in Selenium Webdriver? 

String fontSize = driver.findElement(By.xpath("XPATH_of_the_Element")).getCssValue("font-type");

How to get tooltip text in selenium?

Getting tooltip text of a WebElement is nothing but getting the title attribute of the Webelement in the below manner : 

public String getToolTipData(By locator){

   WebElement element=driver.findElement(locator);
   return element.getAttribute("title");
}

What is StaleElementException? 

Stale Element means that when a Web element is no longer attached with the DOM/WebPage which was present previously. In that case, Selenium throws a staleelementexception.

This may happen for several multiple reasons like due to AJAX or JavaScript calls which changes the state

of the element makes it unavailable/detached from DOM.  

Conclusion : With these we are done with the Sets of Critical Selenium interview questions covering Selenium Framework interview questions , Read through here to get in depth concepts of Selenium to understand the architecture of Selenium.

About Debarghya

Myself Debarghya Roy, I am an Engineering ARCHITECT working with fortune 5 company and an open source contributor, having around 12 years of experience/expertise in various Technology stack.
I have worked with various technologies such as Java,C#,Python,Groovy, UI Automation(Selenium), Mobile Automation(Appium), API/Backend Automation,Performance Engineering(JMeter, Locust), Security Automation(MobSF,OwAsp,Kali Linux, Astra,ZAP etc), RPA,Process Engineering Automation,Mainframe Automation,Back End Development with SpringBoot,Kafka,Redis,RabitMQ,ELK stack, GrayLog, Jenkins and also having experience in Cloud Technologies, DevOps etc.
I live in Bangalore ,India with my wife and have passion towards Blogging , music , playing guitar and my Philosophy of life is Education for All which gave the birth of LambdaGeeks. Lets connect over linked-in - https://www.linkedin.com/in/debarghya-roy/

Leave a Comment

Your email address will not be published. Required fields are marked *