Selenium Interview Question Answer For Fresher and Experienced

.

Top Selenium Interview Question and Answer


Selenium Interview Question Answer


Beginner-Level Selenium Interview Questions
Here, a List of interview questions asked to interview freshers is given.

What are the types of locators in Selenium?
  • ID 
  • Name
  • ClassName
  • LinkText
  • PartialLinkText
  • TagName
  • CssSelector
  • XPath

What are the types of waits supported by WebDriver?
  • Implicit Wait
  • Explicit Wait
  • Fluent Wait

What are the Navigation Methods in Selenium WebDriver?

There are four different navigation commands in Selenium WebDriver:
  • driver.navigate().to(“URL”) 
  • driver.navigate().back() 
  • driver.navigate().forward() 
  • driver.navigate().refresh() 

How to Open Chrome Browser in Selenium WebDriver?

To Launch the Chrome browser in Selenium, first download the Chrome Driver then add the Chrome driver path in the Selenium code as added in the below code.

Selenium Code to launch Chrome browser in Selenium using Java.

Selenium COde

package seleniumproject;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

}


}


How To Open URL in Selenium Webdriver using Java?

Get() Method in selenium is used to open any URL.

Selenium Code to open URLs using Java. 

Selenium Code 

package seleniumproject;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.qaacharya.in/");

}


}


How to Maximize the Browser Window in Selenium Using Java?

Maximize() Mehtod in Selnium is used to maximize the browser window.

Selenium Code to Maximize the Browser Window.

Selenium Code

package seleniumproject;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();

driver.get("https://www.qaacharya.in/");

}


}


How to Rerefrsh the browser Page in Selenium using Java?

Refresh() Method in Selenium is used to refresh the webpage in Selenium.

Selenium Code to Refresh the webpage in Selenium.

Selenium Code

package seleniumproject;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.qaacharya.in/");

driver.navigate().refresh();

}


}


How to Click on the Browser Back Button in Selenium Webdriver using Java?

back() Method in selenium is used to click on the back button of the current browser using Java.

Selenium code to click on the browser back button 

Selenium Code

package seleniumproject;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.qaacharya.in/");

driver.navigate().back();

}


}



How to Click on the Browser Forward Button in Selenium Webdriver using Java?

Forward() Method in selenium is used to click on the Forward button of the current browser using Java.

Selenium code to click on the browser Forward button 

Selenium Code

package seleniumproject;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.qaacharya.in/");

driver.navigate().forward();

}


}


How to Close Browser Window in Selenium using Java?
  • Current Browser Window 
  • All Browse Window
How to Close Current Browser Window in Selenium Using Java?

Close() Method in selenium is used to close the current browser window in selenium . The WebDriver session, however, remains active.

Selenium Code

package seleniumproject;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.qaacharya.in/");

driver.close();

}


}


How to Close All Open Browser Window in Selenium Webdriver Using Java?

quit() Method in selenium is used to close all the browse windows in selenium using Java. ends the WebDriver session.

Selenium Code 

package seleniumproject;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.qaacharya.in/");

driver.quit();

}


}


How To Check if an Element is Present on the Webpage?

isDisplayed() Method in Selenium is used to verify whether the element is present on the webpage or not.

Selenium Code

package seleniumproject;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.facebook.com/");

//To verify that Element is Displayed

Boolean nn =driver.findElement(By.xpath("//input[ @type=\"text\"]")).isDisplayed();

if(nn) {

System.out.println("Yes ! Element is Present");

}

else {

System.out.println("NO ! Element is not Present");

}

}

}


Text Box

How To Type in Textbox using Selenium WebDriver with Java?

SendKeys() Method in selenium is used to enter or type in textbox.

Selenium Code

package seleniumproject;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.facebook.com/");

//To verify that Element is Displayed

WebElement txtbox= driver.findElement(By.xpath("//input[ @type=\"text\"]"));

txtbox.sendKeys("qaacharya.in@gmail.com");

}

}


How to Get the Typed text from textbox in Selenium Using Java?

getAttribute() is used to get the type text from the text box.

Selenium Code

package seleniumproject;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.facebook.com/");

//To verify that Element is Displayed

WebElement Wb= driver.findElement(By.xpath("//input[ @type=\"text\"]"));

Wb.sendKeys("sandeep.uvw@gmail.com");

String txt= Wb.getAttribute("value");

System.out.println(txt);

}

}


How To Validate Enterd or Typed Text in Text Box Selenium Webdriver Using Java?

Contains() is used to validate the typed text in Selenium using Java.

Selenium Code

package seleniumproject;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.facebook.com/");

//To verify that Element is Displayed

WebElement Wb= driver.findElement(By.xpath("//input[ @type=\"text\"]"));

Wb.sendKeys("sandeep.uvw@gmail.com");

String txt= Wb.getAttribute("value");

System.out.println(txt);

if (txt.contains("sandeep.uvw@gmail.com"))

{

System.out.println("Yes text is entered ");

}

else

{

System.out.println("Text is not entered ");

}

}

}


How to Clear the Text Box in Selenium Using Java?

clear() Method in selenium is used to clear the textbox.

Selenium Code

package seleniumproject;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.facebook.com/");

//To verify that Element is Displayed

WebElement txtbox= driver.findElement(By.xpath("//input[ @type=\"text\"]"));

txtbox.sendKeys("qaacharya.in@gmail.com");

txtbox.clear();

}

}

How To Check whether the text box is Blank or Not in Selenium Webdriver Using java?

To check whether the text box is blank or not we use if else to verify.
Check the below code.

Selenium Code

package seleniumproject;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.facebook.com/");

//To verify that Element is Displayed

WebElement Wb= driver.findElement(By.xpath("//input[ @type=\"text\"]"));

String txt= Wb.getAttribute("value");

if(txt.isEmpty())

{

System.out.println(" Yes Text box is blank");

}

else

{

System.out.println("No Text box is not blank");

}

}

}


How do Verify the Placeholder text in Selenium using Java?

Check the below selenium code to verify the placeholder of the text box.

Selenium Code

package seleniumproject;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.facebook.com/");

//To verify that Element is Displayed

WebElement Wb= driver.findElement(By.xpath("//input[ @type=\"text\"]"));

//To check /verify the placeholder in selenium

String plcaehld=Wb.getAttribute("placeholder");

if(plcaehld.equals("Email address or phone number"))

{

System.out.println("Valid Place holder");

}

else

{

System.out.println("invalid place holder");

}

}

}


How to verify element is enabled or disabled in Selenium webdriver Using Java?

isEnabled() Method in selenium is used to verify whether the element is enabled or disabled.

Selenium Code

package seleniumproject;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://www.facebook.com/");

//To verify that Element is Displayed

WebElement Wb= driver.findElement(By.xpath("//input[ @type=\"text\"]"));

//To check /verify the placeholder in selenium

boolean ebabl= Wb.isEnabled();

if(ebabl) {

System.out.println("Yes ! Element is Present");

}

else {

System.out.println("NO ! Element is not Present");

}

}

}

Checkbox

How to Select Checkbox in Selenium Webdriver using Java?

click() method is used to select the checkbox in the Selenium web driver using Java.

Selenium Code

package seleniumproject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://omayo.blogspot.com/");

//To verify that Element is Displayed

WebElement Wb= driver.findElement(By.xpath("//input[@value='blue']"));

Wb.click();

}

}




How to verify whether the Checkbox is selected by default in Selenium Webdriver using Java?

Selenium Code:

package seleniumproject;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://omayo.blogspot.com/");

//To verify that Element is Displayed

WebElement Wb= driver.findElement(By.xpath("//input[@value='orange']"));

boolean ab=Wb.isSelected();

if(ab)

{System.out.println("Checkbox is Selected by Default ");

}

else {

System.out.println("No: Check box is Selected by Default");

}

}

}


How To Check if Checkbox is selected or not If not selected then select the Checkbox in Selenium Webdriver?

Selenium Code

package seleniumproject;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://omayo.blogspot.com/");

//To verify that Element is Displayed

WebElement Wb= driver.findElement(By.xpath("//input[@value='blue']"));

boolean ab=Wb.isSelected();

if(ab)

{System.out.println("Checkbox is Selected by Default ");

}

else {

System.out.println("No: Check box is Selected by Default");

Wb.click();

}

}

}


Radio Button

How to Select the Radio button in Selenium using Java?

click () Method in Selenium is used to select the radio button in the Selenium web driver.

Selenium Code

package seleniumproject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://omayo.blogspot.com/");

//To verify that Element is Displayed

WebElement Wb= driver.findElement(By.xpath("//input[@value='male']"));

Wb.click();

System.out.println("Radio button is selected");

}

}


How to Verify Radion button is selected by Default or not in Selenium Webdriver using Java?

Selenium Code

package seleniumproject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://omayo.blogspot.com/");

//To verify that Element is Displayed

WebElement Wb= driver.findElement(By.xpath("//input[@value='male']"));

boolean ckbx=Wb.isSelected();

if(ckbx)

{

System.out.println("Radio Button is selected by default");

}

else

{

System.out.println("Radio Button is not Selected by default");

}

}

}


How to Verify radion button is Selected by default if not selected then Select the Radio Button using Java?

Selenium Code

package seleniumproject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class LaunchBroswer {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty(

"webdriver.chrome.driver",

"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

// Instantiate a ChromeDriver class.

WebDriver driver = new ChromeDriver();

driver.get("https://omayo.blogspot.com/");

//To verify that Element is Displayed

WebElement Wb= driver.findElement(By.xpath("//input[@value='male']"));

boolean ckbx=Wb.isSelected();

if(ckbx)

{

System.out.println("Radio Button is selected by default");

}

else

{

System.out.println("Radio Button is not Selected by default");

Wb.click();

}

}

}


How To Verify Whether the dropdown is multi-select or Single Select in Selenium Web Driver using Java?


isMultiple() Methos in selenium is used to verify whether the dropdown is multi-select or single-select.

Selenium Code

package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class LaunchBroswer {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
            "webdriver.chrome.driver",
            "D:\\chromedriver-win\\chromedriver.exe");
        // Instantiate a ChromeDriver class.
        WebDriver driver = new ChromeDriver();
        driver.get("https://omayo.blogspot.com/");
       WebElement dpdwn= driver.findElement(By.xpath("//select[@id='drop1']"));
       Select ddwn= new Select(dpdwn);
       boolean vlu=ddwn.isMultiple();
       if(vlu) 
       {
       System.out.println("Yes ! Dropdown is Multi Select");
       }
       else 
       {
       System.out.println("NO ! Dropdwn is Not Multi Select");
       }
}      
}


How to Select the Value From the Dropdown in Selenium Using Java?

There are 3 methods available in selenium to select the value from the dropdown.
  • selectByIndex
  • selectByValue
  • selectByVisibleText
Selenium Code 

package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class LaunchBroswer {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
            "webdriver.chrome.driver",
            "D:\\chromedriver-win\\chromedriver.exe");
        // Instantiate a ChromeDriver class.
        WebDriver driver = new ChromeDriver();
        driver.get("https://omayo.blogspot.com/");
       WebElement dpdwn= driver.findElement(By.xpath("//select[@id='drop1']"));
       Select ddwn= new Select(dpdwn);
      ddwn.selectByValue("def");
}      
}










  • What is Selenium (definition)?
  • What are the Selenium suite components?
  • What are the advantages of using Selenium as an automation tool?
  • What is test automation or automation testing?
  • What are the advantages of automation testing?
  • What is Selenese? How is it classified?

  • What are the limitations of Selenium testing?
  • What is the difference between Selenium 2.0 and Selenium 3.0?
  • What are the testing types supported by Selenium
  • What are the different types of annotations which are used in Selenium?
  • Explain the difference between single slash and double slash in XPath.
  • What is the same-origin policy and how is it handled?
  • Mention the types of Web locators.
  • What are the types of waits supported by WebDriver?
  • Mention the types of navigation commands
  • What is the major difference between driver.close() and driver.quit()?
  • What makes Selenium such a widely used testing tool? Give reasons.
  • Why is it advised to select Selenium as a testing tool for web applications or systems?
  • What is an exception test in Selenium?
  • How to wait until a web page has been loaded completely in Selenium?
  • What is Selenium WebDriver?
  • Is Selenium WebDriver a library?
  • Which browsers/drivers are supported by Selenium Webdriver?
  • Explain Selenium 4 and why it is different from other Selenium versions?
  • What will happen if I execute this command? driver.get
  • What is an alternative option to driver.get() method to open a URL in Selenium Web Driver?
  • Is it possible to test APIs or web services using Selenium Webdriver?
  • How can we move to the nth-child element using XPath?
  • How can we type text in a textbox using Selenium?
  • How to add text in the text box without using sendkeys()?
  • How can you click on a hyperlink in Selenium?
  • What is assertion in Selenium and what are the types of assertion?
  • What is an object repository?

  • Selenium Interview Questions For Experienced
 Mid-Level Selenium Interview Question

  • How to type text in an input box using Selenium?
  • How to scroll down a page using JavaScript?
  • How to assert the title of a webpage?
  • How to mouse hover over a web element?
  • How to retrieve the CSS properties of an element?
  • Can Captcha be automated?
  • How does Selenium handle Windows-based pop-ups?
  • Why do testers choose Selenium over QTP?
  • What are the data-driven framework and keyword-driven framework?
  • What is the difference between getwindowhandles() and getwindowhandle()?
  • What is a Selenium Maven project?
  • What is exactly meant by a WebElement in Selenium, and how is it used?

Hope!!! The above tutorial on Selenium Webdriver interview questions is helpful for you...

Team,
QA acharya

Tags: Selenium interview question and answer, Selenium Interview, Selenium Webdriver interview ,

Post a Comment

0 Comments