Blog | iMocha

120+ Selenium Coding Interview Questions | iMocha

Written by Gemma Benny | 3/19/23 2:01 PM

As businesses embrace automation testing to streamline their web development process, the demand for skilled Selenium developers is rising. According to Enlyft, 78,921 companies use Selenium worldwide.

This makes Selenium a popular framework for the automated testing of web applications, and it supports a variety of programming languages, including Java, Python, C#, Ruby, and JavaScript. It also allows cross-platform compatibility, is an open-source language and can be easily integrated with other tools and frameworks like Jenkins, TestNG, and Cucumber, making it one of the most popular coding languages.

However, recruiters often encounter many challenges while recruiting top talent in this field. Shortage of skilled Selenium developers, varying levels of experience, and vetting and evaluating the skillsets are some of the challenges faced.

So, to hire top talent, recruiters and hiring managers must ask the right selenium coding interview questions.

In this article, we’ll explore 120+ selenium coding interview questions and answers to help you identify the most qualified candidates for the job.

But before that, here are the skills to look out for hiring a Selenium developer.

Technical skills:

  • Proficiency in programming languages, including Java, Python, C#, and JavaScript.
  • A deep understanding of the Selenium framework, including its architecture, components, and capabilities.
  • An experience with automation testing, including knowledge of testing concepts, frameworks, and tools.
  • A Selenium developer should understand web technologies, including HTML, CSS, and JavaScript.
  • Should be familiar with version control systems such as Git, which manages source code and collaborates with team members.
  • Knowledge of software testing methodologies, such as Agile and Scrum.

Soft skills:

In addition to technical skills, several soft skills are essential for Selenium developers to succeed. Here are some:

  • Problem-solving skills: They should have strong problem-solving skills to analyze issues and identify solutions.
  • Communication skills: They must possess excellent communication skills to collaborate effectively with team members and stakeholders.
  • Teamwork: They need to work effectively as a team. This includes sharing knowledge and working collaboratively to achieve project goals.
  • Adaptability: They should be willing to learn and adopt new technologies. This ensures developers stay up-to-date with industry standards.
  • Time management: A Selenium developer must have excellent time management skills to prioritize tasks effectively and efficiently and deliver high-quality work on time.

Top 20 Selenium Coding Interview Questions for Selenium Developer

To make your life easier, we have conducted thorough research and curated a set of selenium coding interview questions and answers that you can utilize to simplify the process of interviewing developers.
 

1. What is Selenium, and what is it composed of?

Selenium is a suite of tools used for automated web testing. It is composed of the following:

  • Selenium IDE (Integrated Development Environment) is a recording and playing-back tool.
  • WebDriver and RC: It offers APIs for various languages like Java, .NET, PHP, etc. With most browsers, Web Driver and RC work.
  • Grid: With Grid, you can distribute tests on multiple machines so that they can run parallel. This helps reduce the time required for running in-browser test suites.

2. How will you find an element using Selenium?

Every object in a web page is referred to as an element. There are various ways to find an element on a web page:

  • ID
  • Name
  • Tag
  • Attribute
  • CSS
  • Link text
  • PartialLink Text
  • Xpath etc
 

Struggling to identify top selenium developers? Discover how iMocha can help you hire high-performing candidates while maintaining the organizational skills bar.

 

 

3. Explain what is an assertion in Selenium and what are the types of assertions?

An assertion is used as a verification point. It verifies the state of the application conforms to what is expected. The types of assertions are “assert,” “verify,” and “waifFor.”

 

4. Mention what the use of X­path is?

X­Path is used to find the WebElement in web pages. It is also helpful in identifying the dynamic elements.

 

5. Explain the difference between single and double slash in X­path?

  • A single slash is used for creating XPaths with absolute paths beginning from the root node.
  • The double slash is used for creating relative XPaths.

 6. List out the technical challenges with Selenium?

The technical challenges with Selenium are:

  • Selenium supports only web-based applications.
  • It does not support the Bitmap comparison.
  • Any reporting-related capabilities have to depend on third-party tools.
  • As there is no object repository in Selenium, the maintainability of objects becomes difficult.

7. What is the difference between type keys and type commands?

  • Type keys usually trigger a JavaScript event, whereas type commands don't.
  • Type keys populate the value attribute using JavaScript, whereas type commands emulate user typing.

8. What are some advantages of Selenium?

The following are the advantages of Selenium: -

  • It is a free, open-source tool without any cost.
  • It supports multiple languages, including Java, Ruby, Python, etc.
  • It supports multi-browser testing.
  • It has numerous resources and helps communities online.
  • Non-programmers can also write scripts using the Selenium IDE component
  • Using the selenium grid component, possible distributed testing can be carried out on remote machines.

9. What are some limitations of Selenium?

Following are the limitations of Selenium: -

  • We cannot test the desktop application using Selenium.
  • We cannot test flash-based apps using Selenium.
  • Programming language knowledge is required to create robust scripts in the selenium web driver.
  • We have to rely on external tools and libraries for performing tasks like - logging(log4J), reading from external files (POI for excels), etc.

10. What is Automation Testing?

Automation testing is the software testing process using automation tools to find defects. In this process, automation tools perform the test scripts and generate the results automatically. Some most popular tools for automation testing are HP QTP/UFT, Selenium WebDriver, etc.

 

11. What are the benefits of Automation Testing?

  • Automation testing is faster in execution and thus saves time and money.
  • Reusability of code: You can create code once and execute it multiple times with less or no maintenance.
  • Easy reporting: Automation testing generates automatic reports.
  • It facilitates compatibility testing by allowing parallel execution in a variety of OS and browser environments.
  • Maintenance is inexpensive: In the long run, it is less expensive than manual testing.
  • Automated testing is more reliable.
  • It is powerful and versatile.
  • It is mostly used for regression testing. Supports execution of repeated test cases.

 

Want to speed up your recruitment process? Learn how Pythian, a global IT consulting company, shortened its hiring process from 90 to 30 days.

 

 

12. What Is WebdriverIO?

WebdriverIO is a robust framework for testing mobile and web applications. It uses JavaScript to implement the Selenium Webdriver API and the wire protocol as per the W3C standards. It is available for installation as an NPM package and runs on Node.js. Hence, it is also famous as “Selenium 2.0 bindings for NodeJS”.

 

13. What are all testing types supported by Selenium WebDriver?

Selenium Webdriver can be used for performing automated functional and regression testing.

 

14. What are the different network protocols that Selenium supports?

HTTP and HTTPS are the two most commonly used network protocols. And in Selenium, there are multiple ways to handle both protocols.

  

15. Mention what the use of X-path is?

The WebElement is located on web pages using X-Path. It also enables the identification of dynamic elements.

 

16. How can we inspect the web element attributes to use them in different locators?

Using Firebug or developer tools, we can inspect the specific web elements. Firebug is a Firefox plugin that provides various development tools for debugging applications. From an automation perspective, firebug is used specifically for inspecting web elements to use their attributes, like id, class, etc., in different locators.

 

17. How can we find an element in Xpath by only partially matching the value of its attributes?

Using contains () method, you can locate an element by partially matching its attribute’s value. This is helpful in scenarios where the attributes have dynamic values with a specific constant part.

xPath expression = //*[contains(@name,'user')] 

The above code will match name attribute values that contain the word 'user.' 

  

18. What is the difference between verify and assert commands?

  • Assert: Assert allows you to check if an element is on the page. The test will stop on the failed step if the asserted element is unavailable. In other words, the test will terminate when the check fails.
  • Verify: The Verify command will determine whether or not the element is on the page. If it is not, the test will continue to run. During verification, all commands are guaranteed to run even if any of the tests fail.

19. While using the click command, can you use screen coordinate?

The clickAT command is used to click on a specific part of an element. The element locator and x, y co­ordinates are accepted as arguments for the clickAt command (locator, cordString).

 

20. What are the four parameters to pass in Selenium?

The four parameters to pass in Selenium are:

  • Host
  • Port Number
  • Browser
  • URL

 

Selenium Coding Interview Questions for Experienced Developers  

Selenium Interview Questions for 5+ years of experience  

1. How can we locate elements using their text in XPath?

Using the text() method: xPathExpression = //*[text()='username'] 

 

2. What is the fastest web driver implementation?

HTMLUnit Driver implementation is the quickest.

 

3. Explain how to assert the webpage's text using Selenium 2.0?

WebElement el = driver.findElement(By.id(“ElementID”))

String text = el.getText();

Assert.assertEquals(“Element Text”, text);

 

4. What is Object Repository?

An object repository is a necessary component of any UI automation. This is because it allows a developer to store all objects used in the scripts in one or more centralized locations rather than scattered throughout the test scripts.

 

Want to maximize your campus hiring efforts? Find out how e-Zest assessed 130 students per campus in just 4.5 hours with iMocha's skill intelligent platform. 

 

 

5. How to send ALT/SHIFT/CONTROL keys simultaneously in Selenium WebDriver?

We hold down these keys and click other buttons to achieve unique functionality. To hold on to these keys, we need to define two more methods apart from keys.ALT or keys.SHIFT or keys.CONTROL functions. To include more than one key to be pressed or released, we can pass ALT, SHIFT, and CONTROL as parameters in the modifier key argument.  

Here is the syntax for the same:

Actions a = new Actions(driver)

a.keyDown(Keys.ALT).keyDown(Keys.SHIFT) .keyDown(Keys.CONTROL).sendKeys('test') .build() .perform();

  

6. How can you upload a file using Selenium WebDriver?

We can upload a file using the element.sendKeys (file path) command. But before doing so, we must use the HTML tag ‘input’ with the attribute type as a file. This helps Selenium identify the web element first and upload the file.

  

7. How can you use regular expressions in Selenium?

Regexp is a keyword that can be prefixed to a text to treat it as a regular expression in Selenium.

 

8. How can you handle colors in a web driver?

We can use the command getCSSValue(arg0) to fetch the colors by sending the color as the argument.  

 

9. Which command takes you forward by one page in the browser history?

The navigate().forward() command takes you forward by one page (previous page) on the browser’s history. This method lets the browser click the forward button in the existing browser window.

 

10. What is POM (Page Object Model)?

Every application webpage has a corresponding page class responsible for locating and performing actions on the web elements. POM is a design pattern that creates object repositories for web elements. It improves code reusability and readability. You can also run multiple test cases on the object repository.

  

11. How can you enable a disabled textbox?

We can enable a disabled HTML element by changing the attributes using the .removeAttribute(“disabled”) method.
Here is a code to allow a text box using the Javascript executor.

String enable ="doc.getElementsByName("name').removeAttribute('disabled');";

javascript.executeScript(enable);

  

12. How can we type text in a textbox element using Selenium?

We can type text in a textbox using the sendKeys() method.

Here is the code:

WebElement searchTextBox = driver.findElement(By.id("srch"));

searchTextBox.sendKeys("searchTerm");

  

13. How can you submit a form in Selenium?

We can submit a form in Selenium using the submit() method.

Here is the code:

driver.findElement(By.id("form1")).submit();

  

14. How do you take a screenshot with Selenium Webdriver?

We can use the TakeScreenshot function to capture the screenshot and getScreenshotAs() command to save the screenshot.

  

15. Which type command should you use if there is a reload event once your typing is completed?

The typeAndWait command can be used when a reload event in the software posts a typing action.

 

16. What’s the difference between close and quit commands?

The distinction between close and quit commands is as follows: -

  • driver.close() - Used to close the currently focused browser.
  • driver.quit() - This function is used to close all browser instances.

17. How to delete cookies in Selenium?

Using the deleteAllCookies() method.

Here is the code:

driver.manage().deleteAllCookies();

 

18. Write the code to double-click an element.

Code to double-click an element: -

Actions action = new Actions(driver);

WebElement element=driver.findElement(By.id("elementId"));

action.doubleClick(element).perform();

 

19. How can we select elements by their attribute value using CSS Selector?

Using [attribute=value], we can select all elements of a specific class. For example, '[type=small]' will select the element with the attribute type of value'small'.

  

20. What is the fundamental difference between XPath and CSS selectors?

The primary distinction between XPath and CSS selector is that XPaths allow us to traverse up in the document, allowing us to move to parent elements. With CSS selectors, we can only move downwards in the document.

  

21. What is Desired capabilities of the selenium web driver?

Desired capabilities are a collection of key-value pairs used in browser instances to store or configure browser-specific properties such as version, platform, and so on.

  

22. How can we find all the links on a web page?

The anchor tag 'a' is used for all of the links. So, by looking for elements of tagName 'a,' we can find all of the links on a page.

Here is the code:

List<WebElement> links = driver.findElements(By.tagName("a"));

  

23. How can we capture screenshots in Selenium?

Using getScreenshotAs method of TakesScreenshot interface, we can take screenshots in Selenium

Here is the code:

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(scrFile, new File("D:\\testScreenShot.jpg"));

 

24. How can we check if an element is getting displayed on a web page?

The isDisplayed method enables us to check if an element is displayed on a web page.

driver.findElement(By locator).isDisplayed();

  

25. Can a captcha be automated?

No, a captcha and barcode reader cannot be automated.

  

26. What is an Object repository?

An object repository is a centralized location for all test script objects or WebElements. Using the Page Object Model and Page Factory design patterns in Selenium, we can create an object repository.

  

27. What is a hybrid framework?

A hybrid framework is a combination of one or more frameworks. It is usually associated with a combination of data-driven and keyword-driven frameworks where the test data and test actions are kept in external files (in the form of a table).

  

28. When do we use Selenium Grid?

We use a selenium grid when we want to run the same or different test scripts on multiple platforms simultaneously. This helps us test under various environments, and the loss of time consumed for testing is reduced.

  

29. What is a node in a selenium grid?

Nodes are machines that are linked to the Selenium grid hub and host Selenium instances that run the test scripts. The selenium grid, unlike the hub, can have multiple nodes.

 

30. Explain the line of code Webdriver driver = new FirefoxDriver();

Webdriver driver = new FirefoxDriver(), refers to creating an object of type WebDriver by implementing an object of the FirefoxDriver class.

 

Selenium Coding Interview Questions for Experienced 10+ Years Developers

1. How can we move to the nth child element using XPath?

Using XPath, there are two ways to get to the nth element:

  • Using index position and square brackets: For example, div[2] will locate the second div element.
  • Position() is used as follows: For instance, div[position()=3] will locate the third div element.

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

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

 

3. How can we move to the parent of an element using XPath?

Using the ‘..’ expression in XPath, we can move to the parent of an element.

  

4. Can Selenium handle pop-up windows?

Selenium is an automation testing tool that can only work with web applications. As a result, Selenium cannot handle the pop-up in windows. However, by integrating with third-party tools, we can overcome this issue.

 

5. What exactly is the distinction between getwindowhandle() and getwindowhandles()?

  • getwindowhandles(): This function retrieves the addresses of all open browsers and returns the data type <SetString>.
  • getwindowhandle() returns the data type String and is used to obtain the address of the currently focused browser window.

6. How can we launch different browsers in the selenium web driver?

By creating an instance of a driver of a particular browser- WebDriver driver = new FirefoxDriver();

  

7. What are regular expressions, and how can you use them in Selenium?

Regular expressions are special text strings that are used to represent search patterns. Regexp is a keyword that can be used as a prefix to treat a text as a regular expression in Selenium.

  

8. Write the code to right-click an element.

Code to right-click an element in Selenium: -

Actions action = new Actions(driver);

WebElement element=driver.findElement(By.id("elementId"));

action.contextClick(element).perform();

  

9. How do you confirm the precise position of a web element?

The commands verifyElementPositionLeft and verifyElementPositionTop are used. These make use of pixel comparison to determine the position of the element from the left and top of the web page.

  

10. How can you redirect browsing from a browser through some proxy?

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

Example:

String PROXY = "199.201.125.147:8080";

org.openqa. Selenium.Proxy proxy = new.org.openqa.selenium.Proxy();

proxy.setHTTPProxy(Proxy)

.setFtpProxy(Proxy)

.setSslProxy(Proxy)

DesiredCapabilities cap = new DesiredCapabilities();

cap.setCapability(CapabilityType.PROXY, proxy);

WebDriver driver = new FirefoxDriver(cap);

 

11. How to type text in a textbox using Selenium?

The sendKeys(“String to be entered”) enter the string in a textbox.

Syntax:

WebElement username = drv.findElement(By.id("Email"));

// entering username

username.sendKeys("sth");

  

12. List the automation tools that can be integrated with Selenium to achieve continuous testing.

Here are some of the automation tools to achieve continuous testing:

  • Jenkins
  • Travis CI
  • CircleCI
  • AWS CodePipeline
  • Azure DevOps
  • Bitbucket Pipelines

13. What are the different types of annotations which are used in Selenium?

The different types of annotations used in Selenium include:

  • @Test - This is used to mark a method as a test method.
  • @BeforeMethod - This annotation can execute a method before each test method.
  • @AfterMethod - This is used to run a method following each test method.
  • @BeforeClass - This annotation specifies that a method should be executed before the first test method.

14. When do you make use of AutoIT?

Selenium is only used to automate web applications. However, if we want to handle, manage, or maintain the GUI, HTML pop-ups, we must use AutoIT.

  

15. In the Selenium web driver, which API is used for database testing?

Selenium employs JDBC (Java Database Connectivity) for database testing. This enables us to create and execute SQL (Structured Query Language) queries.

 

16. Can you explain how the web driver handles colors?

By passing the color as an argument to the command getCssValue(arg0), we can retrieve the colors.

  

17. Which web driver implementation is the fastest?

HTML Unit Driver is the fastest web driver implementation. This is because this driver does not run the tests in the browser but instead runs only plain HTTP, which is faster than expected.

 

18. What exactly are enhanced privilege browsers?

Privileges browsers are similar to Proxy Injection in that they allow websites to do things that are not normally permitted.

  

19. What is the distinction between a get request and a post request?

A get request retrieves data from a server, whereas a post request submits data to a server.

  

20. How can we determine the value of an element's attributes such as name, class, and value?

Using getAttribute(“{attributeName}”) method, we can find the value of different attributes of an element e.g.-

String valueAttribute = driver.findElement(By.id("elementLocator")).getAttribute("value");

  

21. What is an implicit wait in Selenium?

An implicit wait is a type of wait that waits for a specified time while locating an element before throwing NoSuchElementException. By default, selenium tries to find elements immediately when required without any wait. So, it is good to use implicit wait. This wait is applied to all the elements of the current driver instance.
Syntax:

driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

  

22. What expected conditions can be used in Explicit waits?

Some of the commonly used expected conditions of an element that can be used with explicit waits are: -

  • elementToBeClickable(WebElement element or By locator)
  • stalenessOf(WebElement element)
  • visibilityOf(WebElement element)
  • visibilityOfElementLocated(By locator)
  • invisibilityOfElementLocated(By locator)
  • attributeContains(WebElement element, String attribute, String value)
  • alertIsPresent()
  • titleContains(String title)
  • titleIs(String title)
  • textToBePresentInElementLocated(By, String)

23. What is fluent wait in Selenium?

A fluent wait is a type in which we can also specify polling interval(intervals after which the driver will try to find the element) along with the maximum timeout value.  
Syntax:

Wait wait = new FluentWait(driver) .withTimeout(20, SECONDS) .pollingEvery(5, SECONDS) .ignoring(NoSuchElementException.class); WebElement textBox = wait.until(new

Function<webdriver,webElement>() {

public WebElement apply(WebDriver driver) { return driver.findElement(By.id("textBoxId")); }

}

);

  

24. What different keyboard operations can be performed in Selenium?

The different keyboard operations that can be performed in Selenium are:-

  • .sendKeys(“sequence of characters”) - Used for passing character sequence to an input or textbox element.
  • .pressKey(“non-text keys”) - Used for keys like control, function keys, etc, that are non-text.
  • .releaseKey(“non-text keys”) - Used with keypress event to simulate releasing a key from keyboard event.

25. Write the code to double-click an element in Selenium?

Code to double-click an element in Selenium: -

Actions action = new Actions(driver);

WebElement element=driver.findElement(By.id("elementId"));

action.doubleClick(element).perform();

  

26. Write the code to right-click an element in Selenium?

Code to right-click an element in Selenium: -

Actions action = new Actions(driver);

WebElement element=driver.findElement(By.id("elementId"));

action.contextClick(element).perform();

  

27. How to mouse hover an element in Selenium?

Code to mouse hover over an element in Selenium-

Actions action = new Actions(driver);

WebElement element=driver.findElement(By.id("elementId"));

action.moveToElement(element).perform();

  

28. How can we fetch the title of the page in Selenium?

Using driver.getTitle(); we can fetch the page title in Selenium. This method returns a string containing the title of the webpage.

  

29. How can we fetch the page source in Selenium?

Using driver.getPageSource(); we can fetch the page source in Selenium. This method returns a string containing the page source.

  

30. How to verify tooltip text using Selenium?

Tooltips webelements have an attribute of type ‘title’. By fetching the value of the ‘title’ attribute, we can verify the tooltip text in Selenium.

  
Syntax:

String toolTipText = element.getAttribute("title");

 

 

Wondering how to get your candidates to take assessments? Make them fun! Use iMocha's Coding-in-the-blanks, patented tool to create a holistic experience for your candidates and save time!

 

 

Selenium Backend Interview Questions  

1. How to execute javascript in Selenium?

JavaScript can be executed in Selenium using JavaScriptExecuter.

Sample code for javascript execution-

WebDriver driver = new FireFoxDriver();

if (driver instanceof JavascriptExecutor) { ((JavascriptExecutor)driver).executeScript("{JavaScript Code}"); }

  

2. How to handle hidden elements in Selenium webDriver?

Using JavaScript executor, we can handle hidden elements: -

(JavascriptExecutor(driver)) .executeScript("document.getElementsByClassName(ElementLocator).clic k();");

  

3. Name an API used for logging in Java.

Log4j is an open-source API widely used for logging in Java. It supports multiple levels of logging like - ALL, DEBUG, INFO, WARN, ERROR, TRACE, and FATAL.

  

4. Explain the difference between Borland Silk and Selenium is?

Borland Silk

Selenium

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

  

5. Mention why to choose Python over Java in Selenium?

Some advantages of using Python over Java with Selenium include:

  • Java programs run slower than Python programs.
  • Python uses indentation to start and end blocks, whereas Java uses traditional braces.
  • Python is dynamically typed, whereas Java is statically typed.
  • It is less complicated and more compact than Java.

6. Mention which Java API is required to generate PDF reports.

Java API IText is required to generate PDF reports.

  

7. What API is required for database testing in Selenium Webdriver?

JDBC (Java Database Connectivity) API is required for database testing in Selenium Webdriver. It enables you to run SQL statements.

 

8. What is the command that is used to display a variable's values in the output console or log?

  • In order to display a constant string, the command used is echo <constant string>
  • In order to display the value of a variable, you can use a command like an echo ${variable name>>

The above uses PHP. If you use Java, replace echo with System.out.println

 

9. Explain how you can use a recovery scenario with Selenium?

The recovery scenarios are determined by the programming languages you use. If you're using Java, you can get around this by using exception handling by incorporating a "Try Catch Block" into your Selenium WebDriver Java tests.

 

10. Explain how to iterate through options in the test script?

To iterate through options in the test script you can loop features of the programming language. For example, to type different test data in a text box, you can use the “for” loop in Java

// test data collection in an array

String[ ] testData = { “test1” , “test2” , “test3” } ;

// iterate through each test data

For  (string s: test data) {Selenium.type (“elementLocator”, testData) ; }

 

11. In Selenium IDE, how can you generate random numbers and dates for test data?

In Selenium IDE, you can generate random numbers by using Java Script:

  • type
  • css=input#s
  • javascript{Math.random()}
  • And for
  • type
  • css=input#s
  • javascript{new Date()}

12. What is selenium RC (Remote Control)?

In terms of browser and language support, Selenium IDE has limitations.  These limitations can be reduced by using Selenium RC: -

  • Selenium RC is used with languages like Java, C#, Perl, and Python on different platforms and web browsers for automating web applications.
  • It is a java based on and using any language. It can interact with the web application.
  • Using a server, you can bypass the restriction and run your automation script against any web application.

13. Explain what the main difference between web­driver and RC is?

The main difference between Selenium RC and Webdriver is that selenium RC injects javascript function into browsers when the page is loaded. On the other hand, Selenium Webdriver drives the browser using built-in browser support.

 

Struggling to hire for niche roles? Use iMocha and create custom skills assessment to hire job-fit candidates and reduce time to hire by 50%  

 

 

14. Explain how you can capture server-side log Selenium Server?

To capture server side log in Selenium Server, you can use the command: -

java –jar .jar –log selenium.log

 

15. How to execute JavaScript code in Selenium?

JavaScript code can be executed in Selenium using JavaScriptExecuter. Here’s a sample code: -

WebDriver driver = new FireFoxDriver();

if (driver instanceof JavascriptExecutor) { 

((JavascriptExecutor)driver).executeScript("{JavaScriptCode}"); 

}

 

16. What is the use of the testng.xml file?

A testng.xml file is used for configuring the whole test suite. In this file, we can create a test suite, create test groups, mark tests for parallel execution, add listeners, and pass parameters to test scripts. Later, this testng.xml file can be used for triggering the test suite.

 

17. How can we make one test method dependent on others using TestNG?

Using the ‘dependsOnMethods’ parameter inside @Test annotation in TestNG, we can make one test method run only after the successful execution of the dependent test method.

 Syntax:

@Test(dependsOnMethods = { "preTests" })

  

18. How can we set the priority of test cases in TestNG?

Ans. Using the priority parameter in @Test annotation in TestNG, we can define the priority of test cases. When not specified, the default priority of the test is the integer value 0. Example: -

@Test(priority=1)

 

19. What are the commands for downloading Selenium in python?

  • pip install –U selenium
  • sudo pip install python

20. How can we launch Different browsers using python?

  • For Chrome: driver=Webdriver.Chrome(“PathofChromedriver”)
  • For Firefox: driver=webdriver.Firefox(“Path of Firefox Driver”)
  • For IE: driver=webdriver.Ie(“Path of IE Driver”)

Selenium Interview Questions for Freshers

 1. What is Selenium?

Selenium is a robust test automation suite that is used for automating web-based applications. It supports multiple browsers, programming languages, and platforms.

 

2. What are the different components of Selenium?

Selenium has four components-

  • Selenium WebDriver - Selenium WebDriver automates web applications using the browser’s native methods.
  • Selenium IDE - A firefox plugin that works on record and playback principles.
  • Selenium RC - Selenium Remote Control (RC) is officially deprecated by Selenium, and it used to work on javascript to automate web applications.
  • Selenium Grid - Allows selenium tests to run parallel across multiple machines.

3. What is an XPath?

Xpath or XML path is a query language for selecting nodes from XML documents. XPath is one of the locators supported by selenium web driver.

  

4. What is an absolute XPath?

An absolute XPath is a way of locating an element using an XML expression beginning from the root node, i.e., html node in the case of web pages. The main disadvantage of absolute xpath is that even with the slightest change in the UI or any element, the whole absolute XPath fails.

Example - html/body/div/div[2]/div/div/div/div[1]/div/input

 

5. What are various ways of locating an element in Selenium?

The different locators in selenium are-

1. Id

2. XPath

3. cssSelector

4. className

5. tagName

6. name

7. linkText

8. partialLinkText

 

6. Mention what is Selenium 3.0?

Selenium 3.0 is the latest version of Selenium. It has released 2 beta versions of selenium 3.0 with a few of the below changes:

  • It now supports Safari on MacOS via Apple’s safari driver.
  • The minimum requirement is java version 8+.

7. How can we check if an element is enabled for interaction on a web page?

Using the isEnabled method, we can check whether an element is enabled.

Syntax: - driver.findElement(By locator).isEnabled();

  

8. What is a soft assertion in Selenium? How can you mark a test case as failed by using soft assertion?

Soft Assertions are customized error handlers provided by TestNG. Soft Assertions do not throw exceptions when an assertion fails, and they continue to the next test step. They are commonly used when we want to perform multiple assertions.

To mark a test as failed with soft assertions, call the assertAll() method at the end of the test.

  

9. What is Robot API?

Robot API is used for handling Keyboard or mouse events. It is generally used to upload files to the server in selenium automation.

Robot robot = new Robot();

//Simulate enter key action robot.keyPress(KeyEvent.VK_ENTER);

  

10. How to handle HTTPS websites in Selenium? or how to accept an untrusted SSL connection?

Using profiles in Firefox we can handle accepting the SSL untrusted connection certificate. Profiles are a set of user preferences stored in a file.

FirefoxProfile profile = new FirefoxProfile();

profile.setAcceptUntrustedCertificates(true);

profile.setAssumeUntrustedCertificateIssuer(false);

WebDriver driver = new FirefoxDriver(profile);

  

Selenium Developer Behavioral Interview Questions  

1. Describe a situation where you had to explain a technical concept to a client with limited technical knowledge. How did you approach this situation, and what was the outcome?

2. How do you handle disagreements with a team member?

3. How do you ensure everyone on the team knows a project’s progress?

4. What’s your approach to collaborating with someone outside your team to solve a problem? 

5. How do you handle conflicts within your team? Can you give an example of how you have resolved any disputes in the past?

6. Time management has become an essential factor in productivity. Give an example of a time-management skill you’ve learned and applied at work.

7. What projects have you worked on, and how are they relevant to our company’s environment?

8. How do you prioritize tasks with multiple issues or bugs to fix?

9. What’s your approach to handling challenging technical projects?

10. Can you describe a time when you had to adapt to a change in project requirements? How did you handle the situation?

  

Tips for Interviewing Selenium Developers 

During an interview, you have a limited amount of time to gain insight into a candidate's qualifications, background, and character. It is essential to ask the right questions to obtain the most important information. Here are a few tips to help you gather the insights required to hire qualified candidates.

  • List out the essential responsibilities and create questions related to the job role.
  • Share the outline of the interview structure with the candidates. Doing this will keep you both focused and gives the candidate an idea of what to expect.
  • Conduct live coding interviews to observe a developer’s skills, logic, and ability to explain their actions.
  • You can set up a coding test to test developers in one specific programming language or technology.
  • Ask behavioral questions to tap into a developer’s potential to fit into your organization.

 

Want to know how iMocha can help you hire skilled Selenium developers with ease?

Here are a few ways iMocha can help assess the skills of Selenium developers:

  • It offers the world’s most extensive skill assessment library with over 2500+ skills.
  • IMocha's Microsite simplifies the hiring process by enabling direct candidates to register directly. Additionally, recruiters can add assessments to the portal, reducing the need for screening rounds.
  • You can choose from iMocha’s question bank or add custom questions.
  • AI-LogicBox (An innovative pseudo-coding platform) to assess a candidate’s technical skills.
  • Use iMocha’s automated video interviews to quickly assess a developer’s behavioral skills.
  • Live coding Interview offers coding challenges in real-time to assess programming skills.
  • AI-based proctoring to prevent cheating during remote assessments.

 

Need help screening a developer's technical expertise? iMocha Projects enable you to gauge a candidate's potential in a real-life scenario. 

 

 

Conclusion

Formulating the right selenium coding interview questions is integral to the recruitment process. However, companies must also focus on reducing the time-to-hire and increasing the accuracy of candidate evaluations.

This is where an intelligent skills platform like iMocha comes in. By leveraging technology, iMocha provides actionable insights so you can ensure to hire of talented candidates in the shortest time possible. Ultimately, it leads to an organization's success and ability to attract and retain top talent.

  

 FAQ Reference

1. How would you explain the Selenium framework in an interview?

Selenium is an open-source automation testing framework. It is widely used for web applications. With Selenium, developers can automate web browsers across multiple platforms that support languages like Java, Python, C#, Ruby, etc. This framework comprises three main components: Selenium WebDriver, Selenium Grid, and Selenium IDE.

2. What are the four parameters in Selenium?

There are four parameters in Selenium. These include:

  • Browsers
  • Platforms
  • Versions
  • Remote URLs

3. How to handle dropdowns in Selenium?

Dropdowns in Selenium can be handled using the Select class. Here are the steps:

  • Identify the element dropdown using locators like ID, name, class, etc.
  • Next, create an instance of the Select class by passing the dropdown element as a parameter.
  • You can use the Select class method to interact with the dropdown. Standard methods are selectByVisibleText(String text), selectByValue(String value), and selectByIndex(int index).

4. What is POM in Selenium?

POM stands for "Page Object Model." Its design pattern is used to organize code for automated testing of web applications. In POM, each web page is represented by a Java class called a "Page Object." This Page Object comprises methods and elements used to interact with web pages.