Selenium Interview Questions and Answers

Which of the following language is not supported by Selenium
PHP
C#
ASP
Java
Ans – ASP
Which of the following is false in case of waitFor command?
waitForAlertPresent
waitForTextPresent
waitForFramePresent
waitForPageToLoad
Ans – waitForFramePresent
JXL/POI jar files are required to ________.
Requires to verify conditions
In order to use Microsoft Excel files as data source
In order to data drive our test
All of the above
Ans – In order to use Microsoft Excel files as data source
How to create an instance of WebDriver?
WebDriver driver = FirefoxDriver();
WebDriver = new FirefoxDriver();
WebDriver driver = CreateObject FirefoxDriver();
WebDriver driver = new FirefoxDriver();
Ans – WebDriver driver = new FirefoxDriver();
How to navigate to the livetech home page?
Webdriver.get(“http://livetech.co.in”);
driver.navigate(“http://livetech.co.in”);
driver.get(“http://livetech.co.in”);
None of the above
Ans – driver.get(“http://livetech.co.in”);
How to find an element by Name?
WebElement searchBox = driver.findElement(By.name(“someElement”));
WebElement searchBox = findElement(By.name(“someElement”));
WebElement searchBox = driver.findElement(name(“someElement”));
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 _________.
System.out.println(“Title: ” + driver.Title());
System.out.println(“Title: ” + driver.getTitle());
System.out.println(“Title: ” + getTitle());
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’.
selenium.click(“//img[(@id,’cat_prod_image’)]”);
selenium.click(“[starts-with(@id,’cat_prod_image’)]”);
selenium.click(“//img[starts-with(@id,’cat_prod_image’)]”);
None of the above
Ans – selenium.click(“//img[starts-with(@id,’cat_prod_image’)]”);
Which one is not the correct type of locater?
ID
.Name
.DOM
.CSS
.XSD
Ans – .XSD
Which component is not the part of Selenium suite?
SeleniumGrid
Selenium RC
.Selenium IDE
.Selenium Web
Ans – .Selenium Web
Which type of exception is handled during compile time?
Unchecked
Checked
Error
None of the above
Ans – Checked
WebDriver’s Actions commands are
commands that directly interact with page elements
commands that allow you to store values to a variable
commands that verify if a certain condition is met
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?
Fluent Wait
Implicit Wait
Explicit Wait
All of the above
Ans – Implicit Wait
Which WebDriver method is used to clear all selected entries?
dselectAll()
deselectAll()
deselect_All()
dselect_All()
Ans – deselectAll()
What is the similarity between WebDriver’s close() and quit() methods?
does not accept arguments.
closes the active web browser window
closes all opened web browser windows
None of the above.
Ans – does not accept arguments.
Which WebDriver method is used to select the option at a given index?
selectIndex()
selectedByIndex()
selectByIndexes()
selectByIndex()
Ans – selectByIndex()
What is TestNG
TestNextGeneration
TestNewGenerlization
TestNewGeneration
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
//div[contains(@id,’time_’)]
//div[contains(@id_time())]
//div[parameter(@id_time())]
//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)
Collection
Set
List
Map
Ans – List
Attend Free Online Demo of Selenium Online Training
Which of these statements are true. Select the two correct answers.
For each try block there must be at least one catch block defined
A try block may be followed by any number of finally blocks
A try block must be followed by at least one finally or catch block.
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);
}
————–
x = 1
x = 3
Compilation fails
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);
—————-
i = 0
i = 3
i = 5
Compilation fails
Ans – Compilation fails
Select the method which performs a context-click at the current mouse location.
click_Context()
context.Click()
contextClick()
context_Click()
Ans – contextClick() 
Method which selects the option which displays the text matching the parameter passed to it
selectVisibleText()
selectByVisibleText()
select_VisibleText()
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 –
Pre-Req: for Automation
Tool Evaluation
Effort Estimation
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);
 

Questions at

Share your love

One comment

  1. I lovе your blog.. very nice colors & theme. Did you make thiѕ websitе
    yourself or did you hire someone to do it for you? Plz repⅼy as I’m looking to design my own blog
    and would like to find out where u gоt this from. kudos

Leave a Reply