Selenium is an automated testing framework which is designed to automate the test cases for validating the web applications across different browsers and platforms. The tool implements programming languages such as Java, Python, C#, etc for creating the test scripts. The Selenium is a software suite with a list of tools designed to meet the requirement needs of an organization. The list includes.
In this article, you can go through the set of selenium interview questions most frequently asked in the interview panel. This will help you crack the interview as the topmost industry experts curate these at HKR training.
Let us have a quick review of the selenium interview questions.
The reasons are.
Become a master of Selenium by going through this HKR Selenium Training!
Selenium support two types of testing.
The limitations are.
Assert:
The Assert command checks for the condition if true or false. If you assert for an element and want to check if is present in a page or not then the program control will execute the next test if the condition is true else the execution stops and no further test will be executed when the condition becomes false.
Verify:
Verify command also checks for true or false but irrespective of the condition the program execution will not halt. This means any failure during verification won’t stop executing the further test steps.
The following syntax is used in launching the Browser.
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver();
Single slash ‘/ ’:
Double Slash ‘// ’:
WebDriver has two types of waits.
To the visibility of web elements, the WebDriver facilitates the user with the following web elements that can be buttons, drop boxes, checkboxes, radio buttons, labels etc. The methods are.
Syntax:
isDisplayed():
boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();
isSelected():
boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isSelected();
isEnabled():
boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();
The values are selected using WebDriver’s select class.
Syntax:
1. selectByValue:
Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));
selectByValue.selectByValue(“greenvalue”)
2. selectByVisibleText:
Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));
selectByVisibleText.selectByVisibleText(“Lime”);
3. selectByIndex:
Select selectByIndex = new Select(driver.findElement(By.id(“SelectID_Three”)));
selectByIndex.selectByIndex(2);
Single slash ‘/’
Double slash ‘//’
The challenges faced by Selenium are.
The pop-ups are handled using the Alert interface of WebDriver. These four methods used along with Alert interface.
void dismiss() - This method clicks the “Cancel” button when the pop-up window appears.
void accept() - This method clicks the “Ok” button when the pop-up window appears.
String getText() - This method returns the text which is displayed on the alert box.
void sendKeys(String stringToSend) - The sendKeys() enters the specified string pattern into alert box.
Syntax:
// accepting javascript alert
Alert alert = driver.switchTo().alert();
alert.accept();
The parameters are.
Both methods delay the execution speed.
thread.sleep():It stops the current java thread for a specific time period. It can be done only once.
Example: thread.sleep(2000)- It will wait for 2 seconds.
setSpeed():It stops the execution for a specific time period for every selenium command.
Example: selenium.setSpeed(“2000”)- It will wait for 2 seconds.
The setSpeed() is useful in demonstrating or while using a slow web application.
The CSS property values are retrieved using the get() method.
Syntax:
driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);
driver.findElement(By.id(“id“)).getCssValue(“font-size”);
findElement():
findElements():
WebDriver offers a wide range of interaction utilities for users who can also exploit the events of mouse automation and keyboard. Action interface is one utility which simulates the single user interactions.
In this scenario, we use the Action interface to mouse hover on a drop to open a list of options.
Sample Code:
// Instantiating Action Interface
Actions actions=new Actions(driver);
// howering on the dropdown
actions.moveToElement(driver.findElement(By.id("id of the dropdown"))).perform();
// Clicking on one of the items in the list options
WebElement subLinkOption=driver.findElement(By.id("id of the sub link id"));
subLinkOption.click();
Data-driven framework:
In this framework, the test data will be separated and are kept outside the Test Scripts while the logic of Test Case resides inside the Test Scripts. The Test data will be read from external excel files and are loaded into the variables of Test Script. Variables are used for both input and verifications values.
Keyword-driven framework:
This framework requires the development of data tables and keywords that are independent of test automation. In this test, the functionality of an application in the test will be documented in a table as well as step by step instructions for each test.
The JUnits annotation linked with Selenium are.
The five exceptions in Selenium are.
For switching between the frames, the web drivers “driver.switchTo().frame()” takes one of the three possible arguments.
getWindowHandles(): The method is used to get the address of all open browser. The return type of this method is Set
getWindowHandle(): The method is used to get the address of the current browser and the return type of this method is a string.
JXL jar:
POI jar:
Object repository is a term that is used while referring to the collection of web elements which belongs to an Application Under Test (AUT) and its locator values. When an element is required in the script, the locator value is populated from the object repository. Object repository is used for storing the locators in a centralized location instead of hardcoding them within the scripts.
In Selenium, the objects are stored in an excel sheet which can be populated inside the script whenever it is required.
The different types of locators are.
Become a master of Selenium by going through this HKR Selenium Tutorials !
TestNG is a testing framework that is based on JUnit and NUnit which simplifies a broad range of testing needs from unit testing to integration testing. The effective testing framework functionalities are.
The advantages are.
The following code explains how to set priority in TestNG.
Code Snippet:
package TestNG;
import org.testng.annotations.*;
public class SettingPriority {
@Test(priority=0)
public void method1() {
}
@Test(priority=1)
public void method2() {
}
@Test(priority=2)
public void method3() {
}
}
Test Execution Sequence:
WebDriver is used when improvement support is required. The capabilities are of WebDriver includes.
Ans. The following are the various automation tools that can use to integrate with Selenium to accomplish Continuous Testing:-
Ans. An assertion in Selenium is a testing or verification method used to check whether a given condition is true or false. The assertions are useful to verify the state of applications or elements on a page, whether they are present or not. Also, assertions are very important in testing with Selenium as they allow us to verify whether the application's state meets the required expectations.
Ans. XPath refers to XML Path, a language useful to query XML documents and is an approach that helps to detect elements within Selenium. It also includes a path expression having some conditions. Moreover, XPath is also useful for detecting the nodes within XML documents.
Related Article : Selenium Architecture
Ans. XPath Attributes are an essential part of Selenium XPath that is added to the element which contains the most valuable and essential information. These are suggested when no suitable ID is available for the element we want to find out.
XPath Absolute expressions begin with a ("/") single forward slash that defines the document's root element. The simplest type of Selenium XPath allows users to state the full XPath location starting from the root HTML tag to the elements mentioned.
Ans. The following are the primary differences between the driver. quit() and the driver.close() commands.
The driver. quit() command is useful for quitting the driver and closing all the open browser windows.
The driver. close() command is useful to close only the current browser window in focus.
Ans. POM refers to the Page Object Model, a design pattern for building an Object Repository for the web UI (user interface) elements. It helps to improve the readability of the code along with its reusability. Also, we can run many test cases on the object directory. It is because the object directory is free from the selenium test cases.
Ans. The command TypeKeys() activates the JavaScript event in many cases where the command type() doesn't. The value attribute is populated by TypeKey() through JavaScript. But the Type() command copies the typing of the actual user.
Ans. The command "type" is useful for entering the text or values into the text box of the web application. The command "typeAndWait" is also useful for entering the text or value into the web page. But it waits some time to load the page before moving to another command.
The "type" command doesn't wait for the page to load, whereas the "typeAndWait" command waits for the same. If you're not sure about the text, you enter and whether it will or not cause the page to refresh, it is better to use the "typeAndWait" command.
Ans. Automation testing will be highly beneficial to speed up the software testing process. Automation testing saves much time and the resources we spend on manual testing. Moreover, it improves the accuracy of the test cases. It also provides detailed testing reports that help to know the areas of specific attention.
Ans. The following are the various WebDrivers support Mobile testing drivers:-
Ans. Selenese is a set of commands in Selenium useful for web application testing. Moreover, Selenese is a scripting language that helps to write Selenium IDE test scripts. Using the commands of Selenese, a tester can check the broken links, alerts, etc. There are three different Selenese commands Actions, Accessors, and Assertions.
Ans. The following are the different types of element locators in Selenium IDE for finding the web page elements: Html ID, CSS Locators, Html Name, and Xpath locators.
Related Article : Selenium IDE
Ans. Selenium has the following WebDriver APIs:-
Ans. It displays them in XML format.
Ans. Selenium supports the below test types:-
Ans. When we use Selenium WebDriver, we can start applications either using a get() method or a navigate() method. Also, we can use Selenium IDE (a third-party tool) to invoke the applications. But to perform this, you must have the application's URL in advance.
Ans. To obtain the text of a specific web element "get" command is used. The command doesn't need any special parameter, and it gives back a string type value. Moreover, this command verifies the web page's messages, errors, etc.
Ans. The HTMLUnit Driver executes much faster in Selenium.
Ans. A Startpoint is where the execution starts and is useful while running the test script from the center of the code. A breakpoint is useful to terminate or stop the code execution and to check whether the code is working properly as per expectation.
Related Article : What Is XPath In Selenium
Ans. The following are the navigation commands used in Selenium:-
Ans. Below are the two different ways to tailor the TestNG reports in Selenium.
Batch starts on 24th Mar 2023, Fast Track batch
Batch starts on 28th Mar 2023, Weekday batch
Batch starts on 1st Apr 2023, Weekend batch