Selenium Interview Question-1-1
Selenium Interview Question-1-1
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)
Q> What are the challenges you have faced while automating your
application? (Kpit, 3I infotech, Aftek, CMC limited, Nokia Siemens )
Ans:-
Q> What is Alert window/ JavaScript Alert and How to handle alert in
Selenium Webdriver? ( DataMatric, Eclerx)
Ans:- please refer to notes for same .
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 are different types of wait and difference between them?
Which one you have used frequently? (Collabra, Symantec, Balaji
solutions, JP morgan, amazon, )
Ans:- please refer to the notes.
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> Can we capture screenshot only when test fails? (Nihilent, L&T,
KPIT, Nuance)
Ans:- yes. below code will do that
@AfterMethod
Q> How to upload files in Selenium? Have you ever used AutoIT?
(Plivo, Accenture, Igate,capita)
Ans:- Refer notes for same
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)
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
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");
Q>Is there any other way to find xpath other than firebug?
(Synechron)
Ans :- One can right click on Webelement and choose “inspect element
” option.
WebElementGreyColor =
driver.findElement(By.xpath("//*[contains(@class,'yui3-
svgSvgPieSlice')][@fill='#e8cdb7']"));
WebElementLightVioleteColor =
driver.findElement(By.xpath("//*[contains(@class,'yui3-
svgSvgPieSlice')][@fill='#996ab2']"));
WebElementBrownColor =
driver.findElement(By.xpath("//*[contains(@class,'yui3-
svgSvgPieSlice')][@fill='#a86f41']"));
System.out.println(ToolTip.getText());
System.out.println();
driver.navigate().to("http://www.alexa.com/topsites/countries;15/
LU");
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 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);
Q>I have a hidden webelement in a page and like to get the static text.
How to do that? (Eclarx, Accenture)
Ans :-
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);
}
For Chrome :-
DesiredCapabilitieshandlSSLErr = DesiredCapabilities.chrome ()
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true)
WebDriver driver = new ChromeDriver (handlSSLErr);
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
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.