HCL – Selenium Interview Questions
Here is the list of Selenium Interview Questions which are recently asked in HCL company. These questions are included for both Freshers and Experienced professionals. Our Selenium Training has Answered all the below Questions.
1. Explain the Framework you are using
Most used important frameworks are,- Data-Driven Test Framework
- Keyword Driven Test Framework
- Hybrid Test Framework
2. What is data driven framework
Data Driven Framework is one of the popular Automation Testing Framework in the current market. Data Driven automated testing is a method in which the test data set is created in the excel sheet, and is then imported into automation testing tools to feed to the software under test.
Selenium Webdriver is a great tool to automate web-based applications. But it does not support read and write operations on excel files
3. Where the test data will be stored in the FW?
4. Components of Framework
Following are the components of framework- Selenium IDE,
- Selenium RC,
- Selenium WebDriver,
- Selenium RC
5. How to count the links available in the form?
Use the below code for your reference:
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 LinkCount {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = " https://www.credosystemz.com/";
driver.get(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
//Using tagname with anchor
List links = driver.findElements(By.tagName("a"));
System.out.println(“The number of links is “ + links.size());
driver.close();
}
}
6. Different types of locators. Which locator is your preference and why?
Following are the different types of locators,- By CSS ID: find_element_by_id
- By CSS class name: find_element_by_class_name
- By name attribute: find_element_by_name
- By DOM structure or xpath: find_element_by_xpath
- By link text: find_element_by_link_text
- By partial link text: find_element_by_partial_link_text
- By HTML tag name: find_element_by_tag_name
7. Syntax of Xpath and cssSelector
Syntax of Xpath
Xpath=//tagname[@attribute='value']
Syntax of cssSelector
node[attribute_name = ‘attribute_value’]
8. In what format you are giving your report to client
9. Conversion process of Testing report to XSLT
To generate XSLT report in Selenium be ready with below precondition.- Ant should be installed.
- We should have atleast some test case should be executed by TestNG Processor used in report
10. Processor used in report
driver.switchTo().alert();
//Selenium-WebDriver Java Code for entering Username & Password as below:
driver.findElement(By.id("userID")).sendKeys("userName");
driver.findElement(By.id("password")).sendKeys("myPassword");
driver.switchTo().alert().accept();
driver.switchTo().defaultContent();
11. How to handle Authentication window?
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class WindowHandle_Demo {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver","Path to the driver");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
// Load the website
driver.get("http://www.naukri.com/");
// It will return the parent window name as a String
String parent=driver.getWindowHandle();
Sets=driver.getWindowHandles();
// Now iterate using Iterator
Iterator I1= s.iterator();
while(I1.hasNext())
{
String child_window=I1.next();
if(!parent.equals(child_window))
{
driver.switchTo().window(child_window);
System.out.println(driver.switchTo().window(child_window).getTitle());
driver.close();
}
}
//switch to the parent window
driver.switchTo().window(parent);
}
}
12. How to handle multiple window?
package softwareTestingMaterial;
import org.testng.annotations.Test;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class MultipleWindowsClass{
@Test
public void testMultipleWindows() throws InterruptedException{
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\\src\\test\\java\\drivers\\geckodriver.exe");
// To open browser
WebDriver driver=new FirefoxDriver();
// To maximize browser
driver.manage().window().maximize();
// To open Naukri website with multiple windows
driver.get("http://www.naukri.com/");
// It will return the parent window name as a String
String mainWindow=driver.getWindowHandle();
// It returns no. of windows opened by WebDriver and will return Set of Strings
Set set =driver.getWindowHandles();
// Using Iterator to iterate with in windows
Iterator itr= set.iterator();
while(itr.hasNext()){
String childWindow=itr.next();
// Compare whether the main windows is not equal to child window. If not equal, we will close.
if(!mainWindow.equals(childWindow)){
driver.switchTo().window(childWindow);
System.out.println(driver.switchTo().window(childWindow).getTitle());
driver.close();
}
}
// This is to switch to the main window
driver.switchTo().window(mainWindow);
}
}
13. Challenges faced in your automation project and how you overcome those
- Pop-Up Windows
- Identifying Dynamic Elements
- Timeout or Sync Issue
- Limited Reporting
- Limited Captcha Handling
14. How to handle complex interaction – Action class?
15. What kind of Frame work using in your organization?
- Linear Scripting Framework
- Modular Testing Framework
- Library Architecture Testing Framework
- Data-driven Testing Framework
- Keyword Driven Testing Framework
- Hybrid Testing Framework
- Behavior Driven Development Testing Framework
16. Explain about your framework architecure?
17. Where did you stored all kind of xpaths in your framework?
18. What is the HUB & Node?
Selenium Grid a Hub is a server or a central point that controls the test executions on different machines. Node is the machine which is attached to the hub. There can be multiple nodes in Selenium Grid.
19. How do you run your test using a framework?
XPath in Selenium is an XML path used for navigation through the HTML structure of the page. It is a syntax or language for finding any element on a web page using XML path expression. XPath can be used for both HTML and XML documents to find the location of any element on a webpage using HTML DOM structure.
20. Write the xpath?
XPath in Selenium is an XML path used for navigation through the HTML structure of the page. It is a syntax or language for finding any element on a web page using XML path expression.
XPath can be used for both HTML and XML documents to find the location of any element on a webpage using HTML DOM structure.
21. How to handle alerts using web driver?
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.Alert;
public class AlertDemo {
public static void main(String[] args) throws NoAlertPresentException,InterruptedException {
System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Alert Message handling
driver.get("https://www.credosystemz.com/");
driver.findElement(By.name("cusid")).sendKeys("53920");
driver.findElement(By.name("submit")).submit();
// Switching to Alert
Alert alert = driver.switchTo().alert();
// Capturing alert message.
String alertMessage= driver.switchTo().alert().getText();
// Displaying alert message
System.out.println(alertMessage);
Thread.sleep(5000);
// Accepting alert
alert.accept();
}
}
22. How to identify two fields(Radio button) in a page with same id?
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class findElementsTest {
public static void main(String[] args) throws Exception {
// Launch browser
WebDriver driver = new FirefoxDriver();
// Maximize window
driver.manage().window().maximize();
// Navigate to the URL
driver.get("//www.techbeamers.com");
// Sleep for 5 seconds
Thread.sleep(5000);
// Store all the elements of the same category in the list of WebLements.
List list = driver.findElements(By.name("radioButton"));
// Create a boolean variable to store true/false.
Boolean is_selected = list.get(0).isSelected();
// If 'is_selected' is true that means the first radio button is
// selected.
if (is_selected == true) {
// If the first radio button is selected by default then,
// select the second radio button.
list.get(1).click();
} else {
// If the first radio button is not selected then, click the first
// radio button.
list.get(0).click();
}
}
}
23. How to write a xpaths for Dynamic web pages? (like facebook status, Filpakarts)
/* Generic Method */
public void xpathLoc(String identifier){
//The below step identifies the element “First Name” uniquely when the argument is “2”
WebElement E1=d1.findElement(By.xpath("//input[starts-with(@id,”u_0_”+identifier )]"));
E1.sendKeys(“Test1”); /* This step enters the value of First Name as “Test 1” */
}
/* Main Method*/
public static void main(String[] args) {
xpathLoc(“2”); --- This step calls the xpathLoc() method to identify the first name.
}
24. Junit – how do you used in projects?
25. Junit – how do you used in projects?
Free PDF : Get our updated Selenium Course Content pdf
26. How do you handle popup windows in your projects?
Driver.getWindowHandles();
Driver.getWindowHandle();
27. Why is Java platform/OS independent?
It allows its end users to access its source code on any other language automatically.
It’s a human readble language which makes it preferable from a bunch of people.
Its source code can be used to work on a different platform which makes it an independent platform to work on.
28. Have you used collections in your code?
Collection is the root of the collection hierarchy. A collection represents a group of objects known as its elements. The Java platform doesn’t provide any direct implementations of this interface.
29. What is the difference between Implicit and Explicit wait?
Implicit Wait | Explicit wait |
---|---|
The driver is asked to wait for a specific amount of time for the element to be available on the DOM of the page. | The driver is asked to wait till a certain condition is satisfied. |
It affects the execution speed since each step waits for this wait till it gets the element it is looking for. | It does not affect the execution speed since it is applicable to a particular element of the page. |
30. Write any sample code — Fibonacci series … Scenario —
class FibonacciExample1{
public static void main(String args[])
{
int n1=0,n2=1,n3,i,count=10;
System.out.print(n1+" "+n2);//printing 0 and 1
for(i=2;i
31. I have three unique buttons in my page.(Display names are different)
32. The internal ID & Name changes on every page load.
33. I need to click on each button in sequence.
Use the below code:
package pkYourPackage;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
// http://demo.opencart.com/index.php?route=product/category&path=24
public class OpenCart_StackOverflow {
static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:/.....put_ path/chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://demo.opencart.com/index.php?route=product/category&path=24");
try{Thread.sleep(5000);}catch(Exception e){}
List list = driver.findElements(By.xpath("//button[contains(@data-original-title,'Compare this')]/i"));
for(int i = 0 ; i < list.size() ; i++){
list.get(i).click();
try{Thread.sleep(1500);}catch(Exception e){}
}
try{Thread.sleep(1500);}catch(Exception e){}
// click on 'product comparison' to compare
((JavascriptExecutor)driver).executeScript("arguments[0].click();",driver.findElement(By.xpath("//*[contains(text(),'product comparison')]")));
try{Thread.sleep(10000);}catch(Exception e){}
driver.close();
driver.quit();
}
}
34. Write a program to find the largest of 3 numbers
import java.util.Scanner;
public class Biggest_Number
{
public static void main(String[] args)
{
int x, y, z;
Scanner s = new Scanner(System.in);
System.out.print("Enter the first number:");
x = s.nextInt();
System.out.print("Enter the second number:");
y = s.nextInt();
System.out.print("Enter the third number:");
z = s.nextInt();
if(x > y && x > z)
{
System.out.println("Largest number is:"+x);
}
else if(y > z)
{
System.out.println("Largest number is:"+y);
}
else
{
System.out.println("Largest number is:"+z);
}
}
}
Output:
$ javac Biggest_Number.java
$ java Biggest_Number
Enter the first number:10
Enter the second number:17
Enter the third number:15
Largest number is:17
35. Write a program to obtain the ipaddress from the user and chk if the ipaddress is valid or not
import org.apache.commons.validator.routines.InetAddressValidator;
// Java program to validate `IPv4` and `IPv6` address
class Main
{
// an IPv4 address
private static final String INET4ADDRESS = "172.8.9.28";
// an IPv6 address
private static final String INET6ADDRESS =
"2001:0db8:85a3:0000:0000:8a2e:0370:7334";
public static void main(String[] args)
{
// Get an `InetAddressValidator`
InetAddressValidator validator = InetAddressValidator.getInstance();
// Validate an IPv4 address
if (validator.isValidInet4Address(INET4ADDRESS)) {
System.out.print("The IP address " + INET4ADDRESS + " is valid");
}
else {
System.out.print("The IP address " + INET4ADDRESS + " isn't valid");
}
// Validate an IPv6 address
if (validator.isValidInet6Address(INET6ADDRESS)) {
System.out.print("The IP address " + INET6ADDRESS + " is valid");
}
else {
System.out.print("The IP address " + INET6ADDRESS + " isn't valid");
}
}
}
Output:
The IP address 172.8.9.28 is valid
The IP address 2001:0db8:85a3:0000:0000:8a2e:0370:7334 is valid
36. Write a program to check if you have received mail from hcl using webtable
37. Ur project architecture
38. Diff between hashmap and hashtable?
Hashmap | Hashtable |
---|---|
It is the advanced version of HashTable also introduced as a new class in JDK 1.2. | HashTable on the other hand is the legacy class and was introduced prior to HashMap. |
HashMap provides Iterator for its iteration in order to traverse the values stored in it. | Along with Iterator HashTable also provides Enumerator to traverse the values stored in it |
39. What is serialization?
Serialization in Java allows us to convert an Object to stream that we can send over the network or save it as file or store in DB for later usage.
Serialization in Java seems very easy to use at first but it comes with some trivial security and integrity issues
40. What is anonymous class?
Java anonymous class are like local class or inner class without a name. We can use java anonymous class to declare and instantiate a class at the same time.
41. How to create a immutable class?
For example:
import java.util.HashMap;
import java.util.Map;
// An immutable class
public final class Student {
private final String name;
private final int regNo;
private final Map metadata;
public Student(String name, int regNo,
Map metadata)
{
this.name = name;
this.regNo = regNo;
Map tempMap = new HashMap<>();
for (Map.Entry entry :
metadata.entrySet()) {
tempMap.put(entry.getKey(), entry.getValue());
}
this.metadata = tempMap;
}
public String getName() { return name; }
public int getRegNo() { return regNo; }
public Map getMetadata()
{
Map tempMap = new HashMap<>();
for (Map.Entry entry :
this.metadata.entrySet()) {
tempMap.put(entry.getKey(), entry.getValue());
}
return tempMap;
}
}
// Driver class
class Test {
public static void main(String[] args)
{
Map map = new HashMap<>();
map.put("1", "first");
map.put("2", "second");
Student s = new Student("ABC", 101, map);
System.out.println(s.getName());
System.out.println(s.getRegNo());
System.out.println(s.getMetadata());
// Uncommenting below line causes error
// s.regNo = 102;
map.put("3", "third");
System.out.println(s.getMetadata()); // Remains unchanged due to deep copy in constructor
s.getMetadata().put("4", "fourth");
System.out.println(s.getMetadata()); // Remains unchanged due to deep copy in getter
}
}
Output
ABC
101
{1=first, 2=second}
{1=first, 2=second}
{1=first, 2=second}
42. Challenges faced in selenium
- False Positive and False Negative Results
- Captcha or OTP Handling
- Pop up and Alert Handling
- Limited Reporting
43. How will you locate the dynamic objects in a webpage?
Below locators are used to handle the dynamic objects in web page- className
- tagName
- id
- name
- partialText
- linkText
- xpath
- css selector
44. Prog to reverse a string
/ Java program to ReverseString using ByteArray.
import java.lang.*;
import java.io.*;
import java.util.*;
// Class of ReverseString
class ReverseString {
public static void main(String[] args)
{
String input = "credosystemz";
// getBytes() method to convert string
// into bytes[].
byte[] strAsByteArray = input.getBytes();
byte[] result = new byte[strAsByteArray.length];
// Store result in reverse order into the
// result byte[]
for (int i = 0; i < strAsByteArray.length; i++)
result[i] = strAsByteArray[strAsByteArray.length - i - 1];
System.out.println(new String(result));
}
}
Output:
zmetsysoderc
45. Obtain the number of chars in a text file
46. Obtain the number of chars in a text file
47. Read a property file
import java.io.*;
import java.util.*;
public class ReadPropertiesFileTest {
public static void main(String args[]) throws IOException {
Properties prop = readPropertiesFile("credentials.properties");
System.out.println("username: "+ prop.getProperty("username"));
System.out.println("password: "+ prop.getProperty("password"));
}
public static Properties readPropertiesFile(String fileName) throws IOException {
FileInputStream fis = null;
Properties prop = null;
try {
fis = new FileInputStream(fileName);
prop = new Properties();
prop.load(fis);
} catch(FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch(IOException ioe) {
ioe.printStackTrace();
} finally {
fis.close();
}
return prop;
}
}
Output
username: admin
password: admin@123
48. How to handle ajax alerts and frames?
49. Write a java program, to swap without using 3rd variable?
import java.util.*;
class Swap
{
public static void main(String a[])
{
System.out.println("Enter the value of x and y");
Scanner sc = new Scanner(System.in);
/*Define variables*/
int x = sc.nextInt();
int y = sc.nextInt();
System.out.println("before swapping numbers: "+x +" "+ y);
/*Swapping*/
x = x + y;
y = x - y;
x = x - y;
System.out.println("After swapping: "+x +" " + y);
}
}
Output:
Enter the value of x and y
23 43
before swapping numbers: 23 43
After swapping: 43 23
50. Write a Java program to read text from a file and display it.
51. Write a Java program to get file name from the given string.
import java.util.Scanner;
import java.io.*;
public class JavaProgram
{
public static void main(String[] input)
{
String fname;
Scanner scan = new Scanner(System.in);
/* enter filename with extension to open and read its content */
System.out.print("Enter File Name to Open (with extension like file.txt) : ");
fname = scan.nextLine();
/* this will reference only one line at a time */
String line = null;
try
{
/* FileReader reads text files in the default encoding */
FileReader fileReader = new FileReader(fname);
/* always wrap the FileReader in BufferedReader */
BufferedReader bufferedReader = new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null)
{
System.out.println(line);
}
/* always close the file after use */
bufferedReader.close();
}
catch(IOException ex)
{
System.out.println("Error reading file named '" + fname + "'");
}
}
}
import java.io.File;
class Main {
public static void main(String[] args) {
// link to file Test.class
File file = new File("C:\\Users\\Sudip Bhandari\\Desktop\\Programiz\\Java Article\\Test.class");
// get file name using getName()
String fileName = file.getName();
System.out.println("File Name: " + fileName);
}
}
Output
File Name: Test.class
Str = “C:\Programs\TextFile.txt”
Write a sql sub query to join Employee(T1, T2, T3) and return the table 3 values
Write a selenium script to print the table values? Table is like 3X3 table with values A, B, C, 1, 2, 3, 4, 5, 6.
Book a Free Mock Interviews and Test your Selenium skills with our Experts
TOP MNC's SELENIUM INTERVIEW QUESTIONS & ANSWERS
Here we listed all Selenium Interview Questions and Answers which are asked in Top MNCs. Periodically we update this page with recently asked Questions, please do visit our page often and be updated in Selenium.
Related Blogs
To become a Selenium Certified professional and join in your dream company, Enroll now for our Best Selenium Training. We help you to crack any levels of Selenium Interviews and We offering Selenium Training with Placement Assistance.