Selenium Interview Questions and Answers

Selenium Interview Questions and Answers

selenium interview question

Which of the following language is not supported by Selenium

  1. PHP
  2. C#
  3. ASP
  4. Java

Ans – ASP


Which of the following is false in case of waitFor command?

  1. waitForAlertPresent
  2. waitForTextPresent
  3. waitForFramePresent
  4. waitForPageToLoad

Ans – waitForFramePresent


JXL/POI jar files are required to ________.

  1. Requires to verify conditions
  2. In order to use Microsoft Excel files as data source
  3. In order to data drive our test
  4. All of the above

Ans – In order to use Microsoft Excel files as data source


How to create an instance of WebDriver?

  1. WebDriver driver = FirefoxDriver();
  2. WebDriver = new FirefoxDriver();
  3. WebDriver driver = CreateObject FirefoxDriver();
  4. WebDriver driver = new FirefoxDriver();

Ans – WebDriver driver = new FirefoxDriver();


How to navigate to the livetech home page?

  1. Webdriver.get(“http://livetech.co.in”);
  2. driver.navigate(“http://livetech.co.in”);
  3. driver.get(“http://livetech.co.in”);
  4. None of the above

Ans – driver.get(“http://livetech.co.in”);


How to find an element by Name?

  1. WebElement searchBox = driver.findElement(By.name(“someElement”));
  2. WebElement searchBox = findElement(By.name(“someElement”));
  3. WebElement searchBox = driver.findElement(name(“someElement”));
  4. All of the above

Ans – WebElement searchBox = driver.findElement(By.name(“someElement”));


Attend Free Online Demo of Selenium Online Training


Display the title of the page _________.

  1. System.out.println(“Title: ” + driver.Title());
  2. System.out.println(“Title: ” + driver.getTitle());
  3. System.out.println(“Title: ” + getTitle());
  4. None of the above

Ans – System.out.println(“Title: ” + driver.getTitle());


 _________ statement clicks on the first image that has an id attribute that starts with ‘cat_prod_image’.

  1. selenium.click(“//img[(@id,’cat_prod_image’)]”);
  2. selenium.click(“[starts-with(@id,’cat_prod_image’)]”);
  3. selenium.click(“//img[starts-with(@id,’cat_prod_image’)]”);
  4. None of the above

Ans – selenium.click(“//img[starts-with(@id,’cat_prod_image’)]”);


Which one is not the correct type of locater?

  1. ID
  2. .Name
  3. .DOM
  4. .CSS
  5. .XSD

Ans – .XSD


Which component is not the part of Selenium suite?

  1. SeleniumGrid
  2. Selenium RC
  3. .Selenium IDE
  4. .Selenium Web

Ans – .Selenium Web


Which type of exception is handled during compile time?

  1. Unchecked
  2. Checked
  3. Error
  4. None of the above

Ans – Checked


WebDriver’s Actions commands are

  1. commands that directly interact with page elements
  2. commands that allow you to store values to a variable
  3. commands that verify if a certain condition is met
  4. commands that sends key strokes to browser

Ans – commands that directly interact with page elements



What type of Wait objects keep alive until the WebDriver object dies?

  1. Fluent Wait
  2. Implicit Wait
  3. Explicit Wait
  4. All of the above

Ans – Implicit Wait


Which WebDriver method is used to clear all selected entries?

  1. dselectAll()
  2. deselectAll()
  3. deselect_All()
  4. dselect_All()

Ans – deselectAll()


What is the similarity between WebDriver’s close() and quit() methods?

  1. does not accept arguments.
  2. closes the active web browser window
  3. closes all opened web browser windows
  4. None of the above.

Ans – does not accept arguments.


Which WebDriver method is used to select the option at a given index?

  1. selectIndex()
  2. selectedByIndex()
  3. selectByIndexes()
  4. selectByIndex()

Ans – selectByIndex()


What is TestNG

  1. TestNextGeneration
  2. TestNewGenerlization
  3. TestNewGeneration
  4. TestNextGenerations

Ans – TestNextGeneration


If you wanted to access the element that has the text “This element has an ID that changes every time the page is loaded” in it, then which of the following is used

  1. //div[contains(@id,’time_’)]
  2. //div[contains(@id_time())]
  3. //div[parameter(@id_time())]
  4. //div[parameter(@id,’time_’)]

Ans – //div[contains(@id,’time_’)]


What is the name of the Collection interface used to represent elements in a sequence (in a particular order)

  1. Collection
  2. Set
  3. List
  4. Map

Ans – List


Attend Free Online Demo of Selenium Online Training


Which of these statements are true. Select the two correct answers.

  1. For each try block there must be at least one catch block defined
  2. A try block may be followed by any number of finally blocks
  3. A try block must be followed by at least one finally or catch block.
  4. If both catch and finally blocks are defined, catch block must precede the finally block

Ans – c, d


What will be the output of the program?

int x = 3;

int y = 1;

if (x = y){

System.out.println(“x =” + x);

}

————–

  1. x = 1
  2. x = 3
  3. Compilation fails
  4. The code runs with no output.

Ans – Compilation fails


What will be the output of the program?

int i = 0;

while(1) {

if(i == 4)     {

break;

}

++i;

}

System.out.println(“i = ” + i);

—————-

  1. i = 0
  2. i = 3
  3. i = 5
  4. Compilation fails

Ans – Compilation fails


Select the method which performs a context-click at the current mouse location.

  1. click_Context()
  2. context.Click()
  3. contextClick()
  4. context_Click()

Ans – contextClick() 


Method which selects the option which displays the text matching the parameter passed to it

  1. selectVisibleText()
  2. selectByVisibleText()
  3. select_VisibleText()
  4. select_ByVisibleText()

Ans – selectByVisibleText()


Which Framework you have used to Automate your current Project and Describe about them?

Ans – Hybrid Framework

WebDriver + TestNG + Test Suite + Log4j


Write a code to perform mouse Over

Ans –

Import org.openqa.selenium.interactions.Actions;

WebElement mainmenu = driver.findElement(By.name(“name”))

Actions ac = new Actions(driver);

Ac.moveToElement(mainmenu).build().perform();


Explain Frames in WebDriver

Ans –

Frames are subform in a WebPage.To identify the frame will use iframe / frame tag.

driver.switchTo().frame(id/index/name)  — To Enter

driver.switchTo().defaultcontent()  — To Exit


Explain the Automation Testing Process you are following in your current project?

Ans –

  1. Pre-Req: for Automation
  2. Tool Evaluation
  3. Effort Estimation
  4. Framework Creation

Write a code to type the data in Textbox

Ans – Driver.findElement(By.xpath(“xpath of textbox”)).sendKeys(“datatobe type in textbox”);


Write a code To select single value and multiple values from dropdown

Ans –

driver.findElement(By.name(“dropdownname”)).sendKeys(“dropdownvalue”);

(or)

Import org.openqa.selenium.suppourt.ui.Select;

Select st = new Select(driver.findElement(By.name(“dropdownname”));

st.selectByvalue(“value”)

st.selectByindex(index)

st.selectByvisibleText(“Text”)


Explain Wait Methods in WebDriver

Ans –

Thread.sleep()

implicitWait()

explicitWait()


Write a code To read the Data From Excel Using JXL and POI

Ans –

import java.io.FileInputStream;

import jxl.*;

FileInputStream f1=new FileInputStream(“E:\\Selenium\\12345.xls”);

Workbook w1=Workbook.getWorkbook(f1);

Sheet s1=w1.getSheet(“Sheet1”);

int i=2;

String EmpID=s1.getCell(0,i).getContents();

System.out.println(EmpID);

 

import java.io.FileInputStream;

import org.apache.poi.xssf.usermodel.XSSFCell;

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

FileInputStream fis = new FileInputStream(“E:\\Selenium\\123.xlsx”);

XSSFWorkbook workbook = new XSSFWorkbook(fis);

XSSFSheet sheet = workbook.getSheet(“test”);

System.out.println(“Before updating Cell Data “+sheet.getRow(2).getCell(1));


Attend Free Online Demo of Selenium Online Training


Write a code To Handle Alerts in WebDriver

Import org.openqa.selenium.Alert;

Alert a = driver.switchTo().alert();

a.accept();

a.dismiss();


What are the Technical challenges you faced while working with  Selenium Automation

Waiting Time issues

Object identification

Browser compatibility


How To handle Upload and Download Scenarios in Selenium – Explain Briefly

Upload : Using webdriver by providing path of the file

Download : Robot class –using keyboard activities


Write a code To the get Data ,Row Count and Column count of WebTable

To get Data —

String data1 = driver.findElement(By.xpath(“//table[@id=’idCourse’]/tbody/tr[2]/td[2]”)).getText();

System.out.println(data1);

àFor Row Count:

int row =driver.findElements(By.xpath(“//table[@id=’idCourse’]/tbody/tr”)).size();

System.out.println(row);

àFor col Count

int col =           driver.findElements(By.xpath(“//table[@id=’idCourse’]/tbody/tr[1]/td”)).size();

System.out.println(col);


 

Share this post