0% found this document useful (0 votes)
16 views

Selenium Interview Question

Uploaded by

thekingansu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Selenium Interview Question

Uploaded by

thekingansu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Selenium Interview Questions

Selenium Interview Question

Q>What are the advantages of automation testing? (Cybage, Abiba


system)
Ans:-
It supports execution of repeated test cases.
It facilitates parallel execution.
It aids in testing a large test matrix.
It improves accuracy because there are no chances of human errors.
It saves time and money.

Q> Can you please explain Selenium Architecture? (Infy, Cybage,


Emc^2)
Ans:- Language Bindings, JSON Wire Protocol, Browser Drivers, Real
Browsers

Q> What type of test you have automated? (Wipro, techM, infinity)
Ans- Automation mainly focuses on regression testing, smoke testing
and some time you can for End to End test cases.

Q> How many test cases you have automated per day? (Intuit, sears,
Amazon)
Ans- It totally depends on your manual test cases. Sometimes we can
automate 3-4 test cases per day which contain limited operation and
some validation. Some test cases may take 1 day or more than one day
as well.
It totally depends on test case complexity.

Q> How to work with Chrome, IE or any other third party driver? Why
we need separate driver for them? (talentica, xpanxion,vertis,
JaMocha tech)

1 Shammi Jha| 8305429370


Selenium Interview Questions

Ans- Selenium by default supports only Firefox browser so in order to


work with Chrome and IE browser we need to download separate
drivers for them and specify the path.

Q> what are the challenges involved with selenium ( MindTree,


Persistent, Nautica)
Ans:-

1. Generating useful test status reports


1. Dealing with pop-up windows
2. Testing Flash or Silver light apps
3. Unexpected error launching Internet Explorer. Browser zoom level
should be set to 100% by default for the IE browser to overcome this
error
5. Capturing screen shots, either to file or in some form of report

Q> What are the challenges you have faced while automating your
application? (Kpit, 3I infotech, Aftek, CMC limited, Nokia Siemens )
Ans:- At initial stage of automation, during file uploading I faced
challenges because I was not aware with AutoIT.

Q> What is Alert window/ JavaScript Alert and How to handle alert in
Selenium Webdriver? ( DataMatric, Eclerx)
Ans:- driver.switchTo().alert().accept() = To accept the alert
driver.switchTo().alert().dismiss() = to dismiss the alert

Q> Have you ever worked on frames? In addition, how to handle


frames in Selenium? (Fulcrum, cybage, geometric,vertis, NTT data)
Ans:- Please refer to notes for same.

Q> What are different locators available in Selenium? (Real soft, CA


technologies, quest)
Ans:- ID, ClassName, LinkText, partialLinkText, xpath, css, etc

2 Shammi Jha| 8305429370


Selenium Interview Questions

Q> what are different xpath functions ( Target, amazon, cilisious,


capco, sunguard)
Ans:- contains(), starts-with(), text() etc

Q> How to verify checkbox (any element) is enable/disabled/


checked/Unchecked/ displayed/ not displayed? (Xpanxion,
symphony, vodafone, xoriant, igate)
Ans:-
isDisplayed();
isEnabled();
isSelected();
Example:-
System.out.println(radios.get(0).getAttribute("checked")); //is selected
or not

Q> Difference between QUIT and Close? (Infy, tcs, L&T, IBM, Barclays )
Ans:-
driver.close – It closes the the browser window on which the focus is
set.
driver.quit – It basically calls driver.dispose method which in turn closes
all the browser windows and ends the WebDriver session gracefully.

Q> What is default Page Load Timeout in selenium? ( Mastek,


Nihilent)
Ans:- its zero. thats why we need to add waits in our program

Q> What are different types of wait and difference between them?
Which one you have used frequently? (Collabra, Symantec, Balaji
solutions, JP morgan, amazon, )
Ans:- Implicit Wait, Explicit Wait, Fluent Wait

3 Shammi Jha| 8305429370


Selenium Interview Questions

Q> What is JavaScript Executor and where you have used JavaScript
executor? (talentica, Sasken, GE, CGI)
Ans:-
JavaScriptExecutor is an interface which provides mechanism to
execute Javascript through selenium driver.
It provides “executescript” & "executeAsyncScript" methods, to run
JavaScript in the context of the currently selected frame or window.
Sometimes selenium click() does not work, we have used
JavaScriptExecutor to make click happen

Q> How to capture Screenshot in Selenium? (Rediff, Cynapse, IBM)


Ans:-
Below code captures the screenshot
public static void ScreenShot(WebDriver driver,StringscreenshotName)
throws IOException
{
TakesScreenshotts =(TakesScreenshot)driver;
File Source=ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(Source, new
File("./ScreenShots/"+screenshotName+".png"));
}

Q> Can we capture screenshot only when test fails? (Nihilent, L&T,
KPIT, Nuance)
Ans:- yes. below code will do that

@AfterMethod
public void tearDown(ITestResult result) throws IOException
//ITestResult is an interface which give information about our
current test case which is under execution

4 Shammi Jha| 8305429370


Selenium Interview Questions

// result variable will store all the details of @Test along with the
pass or fail result
{
if(ITestResult.FAILURE==result.getStatus())
{
UtilityScrnSht.ScreenShot(Page.driver,
result.getName()); //user created method
}
}

Q> Difference between WebDriverlistner and TestNG listner? Usage


of the same? (Nuance, 3I, Emc2)
Ans:- You must have always craved for more logs from the Webdriver
so that you can debug your scripts or may be log more information
about your tests.
Here is your answer to it, WebDriverEventListner and
TestNgListner(ITestListener Interface.)
In TestNg you can use Listeners in Annotation.
WebDriverEventListener – This is an interface, which have some
predefined methods so we will implement all of these methods.
Difference:- TestNG Listener are triggered at test level such as before
starting test after the test or when test fails etc;
whereas WebDriver Listener are triggered at component level such as
before click, after click etc

Q> How to scroll in Selenium Webdriver? (Persistent, TechM,


dataMatrix, capita)
Ans:- there are two ways to do that
1>use Java Script
Example:- // This will scroll page 400 pixel vertical

5 Shammi Jha| 8305429370


Selenium Interview Questions

((JavascriptExecutor)driver).executeScript("scroll(0,400)");

2> use robot class


Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_PAGE_DOWN);
robot.keyRelease(KeyEvent.VK_PAGE_DOWN);

Q> How to upload files in Selenium? Have you ever used AutoIT?
(Plivo, Accenture, Igate,capita)
Ans:- By the help of AutoIT

Q>Diffrence between findElement and FindElements? (Sonata,


cognizant,capita)
Ans:-
FindElement:- used in targetting single webelement. If targeted
element is not found on the page then it will throw
NoSuchElementException .
FindElements:- used in targetting multiple webelement. If not found
any element on current page as per given element locator mechanism,
it will return empty list.

Q> What is log4j And How to generate log files in Selenium? (Xorient)
Ans:-Log file is just simple file, which keep track of the record or event
or info when any event happens or any software run. This whole
process known as logging.
We can create log file as simple log file as well as HTML format.
Log4j is open source project from Apache which help us achive above
mentioned things.

Q> Explain what is assertion in Selenium and what are the types of
assertion? (Nucleus, persistent, Infosys)

6 Shammi Jha| 8305429370


Selenium Interview Questions

Ans:- Asserts helps us to verify the conditions of the test and decide
whether test has failed or passed. A test is considered successful ONLY
if it is completed without throwing any exception.
Assertions in selenium can be used in 3 modes which are explained
below:
1. assert: If you use assert in your tests then the test will be aborted if
the assert fails. Next test case will start executing in case you are
running a test suite.
2. verify: If verify is used then the test case will not abort even if the
verify fails. It will continue executing and log the failure for the failed
conditions.
3. waitFor: waitFor command waits for the condition to become true. If
the condition is true already the test case continues else it waits for the
conditions to become true. If the condition doesn’t becomes true
within specified time-out period test will fail and halt.

Q> what is the difference between assert and verify in selenium (all
the companies )
Ans:- When an “assert” fails, the test will be aborted.
Where if a “verify” fails, the test will continue executing and logging the
failure.
So when Assertion fails all test steps after that line of code are skipped :
(To resolve this we write this command in try catch block :)

Q> Explain the difference between single and double slash in X-path?
(Magneto, Zenasr)
Ans:-
Single slash ( / ) start selection from the document node
It allows you to create ‘absolute’ path expressions

Double slash ( // ) start selection matching anywhere in the document


It enables to create ‘relative’ path expressions

7 Shammi Jha| 8305429370


Selenium Interview Questions

Q> How to type inside text box without using sendKeys() method
(Pubmatic, BMC, I gate)
Ans:- We need to use JavaScriptExecutor . Refer to Java Script notes for
details
example:-
// Open application
driver.get("enter your application URL");

// This will execute JavaScript in your script


((JavascriptExecutor)driver).executeScript("document.getElementById('
Enter id of input box here').value='Selenium'");

Q> What is better xpath or .css?


Ans :- CSS selectors perform far better than Xpath and it is well
documented in Selenium community. Here are some reasons,
 Xpath engines are different in each browser, hence make them
inconsistent
 IE does not have a native xpath engine, therefore selenium injects
its own xpath engine for compatibility of its API. Hence we lose
the advantage of using native browser features that WebDriver
inherently promotes.
 Xpath tend to become complex and hence make hard to read .
However there are some situations where, you need to use xpath, for
example, searching for a parent element or searching element by its
text

Q> What is WebDriver? (synechron, Hitachi, Simens )


Ans :- Its an interface.

Q> How would you handle dynamic elements while automating?


(Infinite, Wipro, Kretio)
Ans :- We can use Xpath methods such as starts-with or contains()

8 Shammi Jha| 8305429370


Selenium Interview Questions

Q> What are profiles in selenium? (Dautche bank, 3I infotech)


Ans :- This feature is available only with firefox.
If you want to open an instance of firefox which has your plugins &
bookmarks then one can use firefox profile .
FirefoxProfile profile = new FirefoxProfile(new File("D:\\Selenium
Profile"));
WebDriver driver = new FirefoxDriver(profile);

Q>Is there any other way to find xpath other than firebug?
(Synechron)
Ans :- One can right click on Web element and choose “inspect element
” option.

Q> How would you automate charts/graphs/tool tips? (NTT data,JP


Morgan, Mphasis )
Ans:-Many web applications contains charts to show different data In
chart view. One of the chart they are using Is Pie chart. It Is very
Important for us to know how to automate these pie charts In
selenium WebDriver test. Few of the charts are very easy to automate
but It Is very hard to automate some charts as we are unable to locate
parts of pie chart.
@Test
public void pieChart(){
//Locate pie chart elements based on different colors.
WebElementVioleteColor =
driver.findElement(By.xpath("//*[contains(@class,'yui3-
svgSvgPieSlice')][@fill='#66007f']"));
WebElementGreenColor =
driver.findElement(By.xpath("//*[contains(@class,'yui3-
svgSvgPieSlice')][@fill='#295454']"));
WebElementGreyColor =
driver.findElement(By.xpath("//*[contains(@class,'yui3-
svgSvgPieSlice')][@fill='#e8cdb7']"));

9 Shammi Jha| 8305429370


Selenium Interview Questions

WebElementLightVioleteColor =
driver.findElement(By.xpath("//*[contains(@class,'yui3-
svgSvgPieSlice')][@fill='#996ab2']"));
WebElementBrownColor =
driver.findElement(By.xpath("//*[contains(@class,'yui3-
svgSvgPieSlice')][@fill='#a86f41']"));

//locate tooltip pie chart.


WebElement ToolTip =
driver.findElement(By.xpath("//div[contains(@id,'_tooltip')]"));

//Click on pie chart parts and get tooltip values.


System.out.println("-X-X-X-X-X-X-X-X- Violete Part -X-X-X-X-X-X-X-X-");
VioleteColor.click();
System.out.println(ToolTip.getText());
System.out.println();

System.out.println("-X-X-X-X-X-X-X-X- Grey Part -X-X-X-X-X-X-X-X-");


GreyColor.click();
System.out.println(ToolTip.getText());
System.out.println();

System.out.println("-X-X-X-X-X-X-X-X- Light Violete Part -X-X-X-X-X-X-X-


X-");
LightVioleteColor.click();
System.out.println(ToolTip.getText());
System.out.println();

System.out.println("-X-X-X-X-X-X-X-X- Green Part -X-X-X-X-X-X-X-X-");


GreenColor.click();
System.out.println(ToolTip.getText());
System.out.println();

10 Shammi Jha| 8305429370


Selenium Interview Questions

System.out.println("-X-X-X-X-X-X-X-X- Brown Part -X-X-X-X-X-X-X-X-");


BrownColor.click();
System.out.println(ToolTip.getText());
}
}

Q> What is the tag used for links? (unknown)


Ans :- <a>

Q>How to scroll the webpage using webdriver? (Sunguard, Vodafone,


HSBC, Synechron, PGS, Fujitsu)
Ans :- Selenium handle scrolling page automatically but if want to scroll
page using Selenium then yes we can do easily using JavaScript.

We have method scroll(horizontal, vertical) i.e. scroll(0,400)


To execute JavaScript code inside Selenium script we can take the help
of JavascriptExecutor

JavascriptExecutor is an Interface which is available in


package org.openqa.selenium.JavascriptExecutor;
Inside this Interface we have a method called executeScript()- so
whatever script you will pass as a string It will be executed by
JavascriptExecutor.

public class ScrollTestCase {

public static void main(String[] args) throws Exception {

// load browser

11 Shammi Jha| 8305429370


Selenium Interview Questions

WebDriver driver=new FirefoxDriver();

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

// Open Application
driver.get("http://jqueryui.com");

// Wait for 5 second


Thread.sleep(5000);

// This will scroll page 400 pixel vertical


((JavascriptExecutor)driver).executeScript("scroll(0,400)");

There is one more way to do the same .


If you want to use the keys form the keyboard to scroll UP or
DOWN you can use the WebDriver sendKeys() method and pass
the PAGE_UP or PAGE_DOWN as an argument:
@Test(groups = {"smoke"})
public void test_Scroll_Page_Using_Keys() throws Exception {
init();

driver.navigate().to("http://www.alexa.com/topsites/countries;15/
LU");

12 Shammi Jha| 8305429370


Selenium Interview Questions

Actions action = new Actions(driver);


action.sendKeys(Keys.PAGE_DOWN);
waitSeconds(2);
action.click(driver.findElement(By.partialLinkText("Google.com.ph")))
.perform();
}

Q>How to find the present URL on the application? (Persistent,


accenture)
Ans :- WebDriver driver =newWebDriver();
Stringurl=driver.getCurrentUrl();

Q>How to find the number of browsers opened by selenium?


Ans :- driver.getWindowHandles()

Q> how to use open new tab in existing browser (One network, media
ocean, PTC)
Ans :-

driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL,"t");
or
driver.navigate().to(urlToOpen);

Actions action =newActions(driver);


// close the newly opened tab
action.keyDown(Keys.CONTROL).sendKeys("w").perform();
// switch back to original
action.keyDown(Keys.CONTROL).sendKeys("1").perform();
Ctrl+t combination to open a new tab, Ctrl+w to close it, and to switch
back to original tab I used Ctrl+1 (the first tab).

Q>How will you simulate a keyboard action using webdriver?

13 Shammi Jha| 8305429370


Selenium Interview Questions

Ans :- Please refer to notes

Q>Write a sample code to perform browser refresh(Amazon,


prospance, quest, Dautche bank)
Ans :- there are multiple ways to do it
1.driver.navigate().refresh();
2.driver.get(driver.getCurrentUrl());
3.driver.navigate().to(driver.getCurrentUrl());
4.driver.findElement(By.id("Contact-us")).sendKeys(Keys.F5);
5.driver.executeScript("history.go(0)");

Q>Difference between click and clickandwait() statements? (Sapient )


Ans :- click command only execute the command and then proceed to
next command of the script.
"clickAndWait" command is some different than "click" command. It
will wait for page to load means next command will be not executed
until page not loaded successfully. You need to use this command when
your
are clicking somewhere on page of software web application and page
start reloading content.

Q>How to run the selenium webdriver scripts in the background? Write


a sample code to perform that action. (Accenture, CGI, Lloyds)
Ans :- To achieve this one has to use either HtmlUnitDriver or
PhantomJS

Q>I have a hidden webelement in a page and like to get the static
text. How to do that? (Eclarx, Accenture)
Ans :-

14 Shammi Jha| 8305429370


Selenium Interview Questions

Since a user cannot read text in a hidden element, WebDriver will not
allow access to it as well. However, it is possible to use Javascript
execution abilities to call getText directly from the element..."
publicstaticStringgetText(WebDriver driver,WebElement element){
return(String)((JavascriptExecutor) driver).executeScript(
"return jQuery(arguments[0]).text();", element);
}

Q>How do I know when a page has finished loading? (one network )


Ans :- Selenium does this by default for us.

Q>How do you handle secured connection error in HTTPS ? (Sunguard,


Infosys, Cybage)
Ans :-
For Firefox :-
//Creating new Firefox profile
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
driver = new FirefoxDriver(profile);

For Chrome :-
DesiredCapabilitieshandlSSLErr = DesiredCapabilities.chrome ()
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true)
WebDriver driver = new ChromeDriver (handlSSLErr);

Q>Does WebDriver support file uploads? (unknown)


Ans :- No

15 Shammi Jha| 8305429370


Selenium Interview Questions

Q>I got an unexpected pop up/alert error in my screen, how will you
handle in your script? (Unknown)
Ans :- refer popup and alert notes for same

Q> How to highlight webElement in Selenium? (Synechron,


A4SureTech, Sasken)
For example :-

Ans :-
driver.get("http://www.facebook.com");

// Create the JavascriptExecutor object


JavascriptExecutorjs=(JavascriptExecutor)driver;

// find element using id attribute


WebElement username= driver.findElement(By.id("email"));

// call the executeScript method


js.executeScript("arguments[0].setAttribute('style,'border: solid 2px
red'');", username);

Q> how to find out xpath or view dom when test case is already
running (Barclays, Amdocs, cognizant)
Ans :- You will have to create firefoxprofile and add the firebug and
firepath plugins into that.

16 Shammi Jha| 8305429370

You might also like