Selenium Real Time Interview Questions
Selenium Real Time Interview Questions
between
architecture
Selenium
is
way
more
RC
and
Selenium
Get method will get a page to load or get page source or get text that's all whereas
navigate
will guide through the history like refresh, back, forward. For example if we want
to
move
forward and do some functionality and back to the home page this can be
achieved
through navigate() only. driver.get will wait till the whole page gets loaded and
driver.navigate
will just redirect to that page and will not wait
Please tell me the difference b/w implicitly Wait and Explicit wait.
Implicit Wait sets internally a timeout that will be used for all consecutive Web
Element searches. It will try lookup the element again and again for the specified
amount of time before throwing a NoSuchElementException if the element could
not have been found. It does only this and can't be forced into anything else - it
waits for elements to show up.
Explicit Wait or just Wait is a one-timer used by you for a particular search. It is
more extendible in the means that you can set it up to wait for any condition you
might like. Usually, you can use some of the prebuilt Expected Conditions to wait
for elements to become clickable, visible, invisible, etc., or just write your own
condition that suits your needs.
How we can retrieve the dynamically changing Ids? When we login Facebook the
login label's id changes dynamically thus resulting in failure.
We have a hierarchy of locators and Facebook Is dynamic in nature,so we are not
able
to
use "id" for identification for after that we have remaining 7 locator's for that :2.
xpath
()..
3. name..4. css.. 5. link text.. 6. Partial link text...7.tag name. so u can use any one
for
identifying it. Most probably u can use "xpath" or "css-locator" and if there r tag
then
link text or partial-link text. it depend on u . But we never use id's in Ajax
application
because its not possible.
15.What is the difference between driver.Close() and driver.Quit () method?
Close() - It is used to close the browser or page currently which is having the focus.
Quit() - It is used to shut down the web driver instance or destroy the web driver
instance
(Close all the windows)
How to scroll web element?--not browser
FirefoxProfile profile=new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver=new FirefoxDriver(profile);
driver.navigate("http://jqueryui.com/draggable/");
Thread.sleep(6000L);
WebElement element=driver.findElement(By.xpath("//div[@id='draggable']"));
Actions actn=new Actions(driver);
actn.dragAndDropBy(element, 50, 50).build().perform();
}
What is the basic use of Firefox profiles and how can we use them using selenium?
A profile in Firefox is a collection of bookmarks, browser settings, extensions,
passwords,
and history; in short, all of your personal settings.
We use them to change user agent, changing default download directory, changing
versions etc.
Customize the name of file going to be downloaded?
You have to download AUTO IT.exe file and has to be install
and later you have create .au3 file (in this file you have to specify the commands in
VB script like your file name, where have to save, it will be easy may be 3 or 4
steps
)
using AUTOIT...then right click the .au3 file you have to compile ....after that you
will
get the .exe file with the name of .au3 file ..In eclipse you will give the code like
this
<----ProcessBuildder ps = new ProcessBuilder("path of the .exe file of au3")
.start();--->
How to handle internationalisation through web driver?
FirefoxProfile profile = new FirefoxProfile();
profile.set Preference("intl.accept_languages","jp");
Web driver driver = new FirefoxDriver(profile); driver.get(google.com) will open
google
in
Japanese Lang
How to overcome same origin policy through web driver?
Proxy server.
DesiredCapabilities capability=new DesiredCapabilities.firefox();
capability.setCapability(CapabilityType.PROXY,"your desire proxy")
WebDriver driver=new FirefoxDriver(capability);
How to put text in Facebook search box using selenium web driver.
driver.findElement(By.xpath("//div[contains(@class, '_586i')]")).sendKeys("abc");
Difference between flex and flash application.
In flash there is no code just based on creativity(design) we will complete the
work(time consuming process) whereas flex contain some small functions
which is integrated with mxml,PHP..(no tool is there to develop
flex we want to use the properties of css and style sheet)
What is Error Collector in TestNG?
What is its use?
This class allows the collection of errors during the process of retrieving the
test data for the test method parameters
How can we get the font size, font color, font type used for a particular text on a
webpage using Selenium web driver?
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-size);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-colour);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-type);
driver.findelement(By.Xpath("Xpath ").getcssvalue("background-colour);
How to run tests in multiple browser parallel?
Is there any other option other than selenium grid?
You create a class with a method something like this:
public class LaunchBrowser {
WebDriver driver=null;
// Pass parameter browser from test.xml
@Parameters(browser)
public void initiateBrowser(String browser){
// compare browser to fire fox and then open firefox driver
if(browser.equals(Firefox))
{
driver = new FirefoxDriver();
}
else
{
\ set path to the IE driver correctly here
System.setProperty("webdriver.ie.driver", "\iexploredriver.exe");
driver =new InternetExplorerDriver();
}
}
Now create YourClassName class and call extend the above class something like
this
@Test
public class YourClassName extends LaunchBrowser{
public void gotoGoogle(){
driver.get(http://www.google.com");
}
}
How to prepare Customized html Report using TestNG in hybrid framework.
Below are the 3 ways:
Junit: with the help of ANT.
TestNG: using inbuilt default.html to get the HTML report. Also XST reports from
ANT,
Selenium, TestNG combination.
Using our own customized reports using XSL jar for converting XML content to
HTML.
Whats the hierarchy of TestNG annotations?
Explain me about annotation hierarchy & execution order?
org.testng.annotations.Parameters (implements java.lang.annotation.Annotation)
org.testng.annotations.Listeners (implements java.lang.annotation.Annotation)
org.testng.annotations.Test (implements java.lang.annotation.Annotation)
org.testng.annotations.AfterMethod (implements java.lang.annotation.Annotation)
org.testng.annotations.BeforeTest (implements java.lang.annotation.Annotation)
org.testng.annotations.BeforeMethod
(implements
java.lang.annotation.Annotation)
org.testng.annotations.Optional (implements java.lang.annotation.Annotation)
org.testng.annotations.AfterTest (implements java.lang.annotation.Annotation)
org.testng.annotations.Guice (implements java.lang.annotation.Annotation)
org.testng.annotations.BeforeGroups
(implements
java.lang.annotation.Annotation)
org.testng.annotations.ExpectedExceptions
(implements
java.lang.annotation.Annotation)
org.testng.annotations.TestInstance (implements java.lang.annotation.Annotation)
org.testng.annotations.NoInjection (implements java.lang.annotation.Annotation)
org.testng.annotations.AfterSuite (implements java.lang.annotation.Annotation)
org.testng.annotations.AfterClass (implements java.lang.annotation.Annotation)
org.testng.annotations.AfterGroups (implements java.lang.annotation.Annotation)
org.testng.annotations.DataProvider (implements java.lang.annotation.Annotation)
org.testng.annotations.BeforeSuite (implements java.lang.annotation.Annotation)
org.testng.annotations.BeforeClass (implements java.lang.annotation.Annotation)
org.testng.annotations.Factory (implements java.lang.annotation.Annotation)
org.testng.annotations.Configuration
(implements
java.lang.annotation.Annotation)
org.testng.annotations.ObjectFactory
(implements
java.lang.annotation.Annotation)
How the TestNG interacts with Selenium Core?
Explain me steps and internal architecture?"
What is TestNG?
So far we had been doing Selenium tests without generating a proper format for
the test results. From this point on, we shall tackle how to make these reports
using a test framework called TestNG.
TestNG is a testing framework that overcomes the limitations of another popular
testing framework called JUnit. The "NG" means "Next Generation". Most Selenium
users use this more than JUnit because of its advantages. There are so many
features of TestNG, but we will only focus on the most important ones that we can
use in Selenium.Advantages of TestNG over JUnit
There are three major advantages of TestNG over JUnit:
Annotations are easier to understand Test cases can be grouped more easily
Parallel testing is possible
Is it possible test web services using selenium?
Using Jmeter we can test how one website is talking to each other means time
taken
to
send data, feeds, messages from one website to other website. Jmeter does a nice
job
of doubling for performance and api tests.
How to refresh a page without using context click?
1.Using sendKeys.Keys method
2.Using navigate.refresh() method
3.Using navigate.refresh() method
4.Using get() method
5.Using sendKeys() method
1.Using sendKeys.Keys method
driver.get("https://accounts.google.com/SignUp");
driver.findElement(By.id("firstname-placeholder")).sendKeys(Keys.F5);
2.Using navigate.refresh() method
driver.get("http://ruchi-myseleniumblog.blogspot.in/2013/12/100-seleniuminterview-questions.html");
driver.navigate().refresh();
3.Using navigate.to() method
driver.get("http://ruchi-myseleniumblog.blogspot.in/2014/01/selenium-hybridframework-using.html");
driver.navigate().to(driver.getCurrentUrl());
4.Using get() method
driver.get("http://ruchi-myseleniumblog.blogspot.in/2013/12/basic-core-javainterview-questions.html");
driver.get(driver.getCurrentUrl());
5.Using sendKeys() method
driver.get("https://accounts.google.com/SignUp");
driver.findElement(By.id("firstname-placeholder")).sendKeys("\uE035");
Can u send a code for printing in selenium?
There are two cases:
Case1. Any hyperlink/button on a web page, n clicking that link/button a print
dialog
box
opens. (Performing an action on web page)
Case2.or do u want to open print dialog box within ur own script, not by performing
any
action on web page.
So If Case 1: just a call for WebElement.click() event will work to open it.
If Case 2: Call a Printer Job object (Use Awt API).
For code: Google it.
How to find broken images in a page using Selenium Web driver.
Get xpath and then using tag name; get all the links in the page Click on each and
every link in the page
In the target page title, look for 404/500 error.
How to find broken images in a page using Selenium package programs;
import
import
import
import
import
import
import
import
java.util.List;
org.apache.http.HttpResponse;
org.apache.http.client.methods.HttpGet;
org.apache.http.impl.client.DefaultHttpClient;
org.openqa.selenium.By;
org.openqa.selenium.WebDriver;
org.openqa.selenium.WebElement;
org.openqa.selenium.firefox.FirefoxDriver;
driver.findElement(By.id("your searchButton")).click();
(i.e., the developer) identify appropriate tests to writethat is, tests that reflect
the behavior desired by the stakeholders. BDD is usually done in very English-like
language helps the Domain experts to understand the implementation rather than
exposing the code level tests. Its defined in a GWT format, GIVEN WHEN & THEN.
How to change user agent in Firefox by selenium web driver.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "some UA string");
Web Driver driver = new FirefoxDriver(profile);
What is Selenese?
Selenese is HTML language based command, which is used in Selenium IDE.
Differences between QTP and selenium.
1) Selenium generates a proxy while starting browser. QTP does not
2) QTP uses only Vb script. Selenium is available in many languages
3) QTP is paid and selenium is free.
4) You can run script from a particular line in QTP but in selenium, you cannot.
5) Selenium works on all browsers. QTP only works on IE, mozilla. Support from
chrome has been introduced lately.
6) QTP is more organized and user friendly
7) Selenium requires more technical skills
8) QTP can also be used on desktop based applications but selenium cannot be
used
What is the MOST challenging test problem in my career in Automation?
In my career
Changing XPATHS' between testing server and production server-by keeping
generic xpath
Keep separate property files for production and UAT
automating flash apps
Mobile Automation
Suppose developer changed the existing image to
new image with same xpath. Is test case pass or fail?"
Pass
How to handle network latency using selenium?
Using driver.manage.pageLoadingtime for network latency
How does u handle dynamic elements without using xpath (with example?)
By using classname or css.
What are the different types of driver implementation?
AndroidDriver, AndroidWebDriver, ChromeDriver, EventFiringWebDriver,
FirefoxDriver, HtmlUnitDriver, InternetExplorerDriver, IPhoneDriver,
IPhoneSimulatorDriver, RemoteWebDriver, SafariDriver, WebDriverBackedSelenium
Code for Opening Firefox browser?
Webdriver driver=new FireFoxdriver();
Which repository you have used to store the test scripts?
I have created scripts in excel file and store them in Test cases folder under src .
How to work with radio button in web driver?
We can select the value from the drop down by using 3 methods.
selectByVisibleText - select by the text displayed in drop down
selectByIndex - select by index of option in drop down
selectByValue - select by value of option in drop down
<select id="44"><option value="1">xyz</option>
<option value="2">abc</option>
<option value="3">pqr</option>
</select>
WebElement e = driver.findElement(By.id("44"));
Select selectElement=new Select(e);
// both of the below statements will select first option in the weblist
selectElement.selectByVisibleText("xyz");
selectElement.selectByValue("1");
How to work with dynamic web table?
You can get the total number of <tr> tags within a <td> tag by giving the xpath of
the
<td> element by using this function List<WebElement> ele = driver.findElements(By.xpath("Xpath of the table"));
Now you can use a for each loop to loop through each of the <tr> tags in the above
list
and then read each value by using getText() method.
Detail about TestNG Test Output folder.
It is the directory where reports are generated. Every time tests run in a suite,
TestNG
creates index.html and other files in the output directory.
In frame if no frame Id as well as no frame name then which attribute I should
consider throughout our script.
You can go like this.....driver.findElements(By.xpath("//iframe"))...
Then it will return List of frames then switch to each and every frame and search
for the locator which you want then break the loop
What is object repository?
It is collection of object names their properties, attributes and their values .It maye
be excel, XML,property file or text file
TestNG vs. Junit?
Advantages of TestNG over Junit
In Junit we have to declare @BeforeClass and @AfterClass which is a constraint
where as in TestNG there is no constraint like this.
Additional Levels of setUp/tearDown level are available in TestNG like
@Before/AfterSuite,@Before/AfterTest and @Before/AfterGroup. No Need to extend
any class in TestNG.
There is no method name constraint in TestNG as in Junit. You can give any name to
the test methods in TestNG
In TestNG we can tell the test that one method is dependent on another method
where as in Junit this is not possible. In Junit each test is independent of another
test.
Grouping of testcases is available in TestNG where as the same is not available in
Junit.
Execution can be done based on Groups. For ex. If you have defined many cases
and segregated them by defining 2 groups as Sanity and Regression. Then if you
only want to execute the Sanity cases then just tell TestNG to execute the
Sanity and TestNG will automatically execute the cases belonging to the Sanity
group. Also using TestNG your selenium test case execution can be done in parallel.
What is the difference between @before method and @beforeclass.
In JUnit4 @Before is used to execute set of preconditions before executing a test.
For example, if there is a need to open some application and create a user
before executing a test, then this annotation can be used for that method. Method
that is marked with @Before will be executed before executing every test in the
class.
If a JUnit test case class contains lot of tests which all together need a
method which sets up a precondition and that needs to be executed before
executing the Test Case class then we can utilise @BeforeClass annotation.
import org.openqa.selenium.interactions.Actions;
public class testResizable {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://jqueryui.com/resources/demos/resizable/default.html");
WebElement resize = driver.findElement(By.xpath("//*[@id='resizable']/div[3]"));
Actions action = new Actions(driver);
action.dragAndDropBy(resize, 400, 200).perform();
}
}
Difference between the selenium1.0 and selenium 2.0?
Selenium 1 = Selenium Remote Control.
Selenium 2 = Selenium Web driver, which combines elements of Selenium 1 and
Web driver.
Difference between find element () and findelements ()?
findElement() :
Find the first element within the current page using the given "locating
mechanism".
Returns a single WebElement.
findElements() :
Find all elements within the current page using the given "locating mechanism".
Returns List of Web Elements.
How to take the screen shots in seelnium2.0?
// store screenshots
public static void captureScreenShot(String filePath) {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(filePath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
What is the default time for selenium Ide and webdriver?
Default timeout in selenium ide is 30 seconds.
Write down scenarios which we can't automate?
Barcode Reader, Captcha etc.
In TestNG I have some test's Test1-Test2-Test3-Test4-Test5I want to run my
execution order is Test5-Test1-Test3-Test2-Test4.How do you set the execution order
can you explain for that?
Use priority parameter in @test annotation or TestNG annotations.
Differences between jxl and ApachePOI.
jxl does not support XLSX files
jxl exerts less load on memory as compared to ApachePOI
jxl doesn't support rich text formatting while ApachePOI does.
jxl has not been maintained properly while ApachePOI is more up to date.
Sample code on Apache POI is easily available as compare to jxl.
How to ZIP files in Selenium with an Example?
// Sample Function to make zip of reports
public static void zip(String filepath){
try
{
File inputFolder=new File('Mention file path her");
File outputFolder=new File("Reports.zip");
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new
FileOutputStream(outputFolder)));
BufferedInputStream in = null;
byte[] data = new byte[1000];
String files[] = inputFolder.list();
for (int j=0; j<files.length; i++)
{
in = new BufferedInputStream(new FileInputStream
(inputFolder.getPath() + "/" + files[j]), 1000);
out.putNextEntry(new ZipEntry(files[j]));
int totalcount;
while((totalcount= in.read(data,0,1000)) != -1)
{
out.write(data, 0, totalcount);
}
out.closeEntry();
}
out.flush();
out.close();
}
catch(Exception e)
{
e.printStackTrace();
return "Fail - " + e.getMessage();
}
}
What is default port no?
4444
If Default port no is busy how to change port no?
We can use any port number which is valid. First create an object to remote control
configuration.
Use 'setPort' method and provide valid port number (4545, 5555, 5655, etc). There
after
attach
this
remote control configuration object to selenium server. i.e
RemoteControlConfiguration r= new RemoteControlConfiguration();
r.setPort(4567);
SeleniumServer s= new SeleniumServer(r);
Does Selenium support https protocols? Yes
Majorly asked test scenario with framework in Interviews?
Majorly asked are:
Login for Gmail scenario
Goggle search and finding no of results
Downloading a file and save it
Checking mails and deleting them
Do shopping in flipkart.com
Selenium support mobile applications?
No, it is browser automation tool, it only automates Websites opening in mobile
browser, and mobile APPs
can't be automated.
What is wraps Driver?
For casting selenium instance to selenium2 (webdriver). wraps driver is used.
For more details.
Can you explain Junit Annotation? If there are 1000 test cases. 500 test cases are
executed. How will you execute the rest of the test cases by using annotation?"
The annotations generated with JUnit 4 tests in Selenium are:
@Before public void method() - Will perform the method() before each test. This
method can prepare the test
@Test public void method() - Annotation @Test identifies that this method is a
test method.environment,e.g. read input data, initialize the class)
@After public void method() - Test method must start with test@Before - this
annotation is used for executing a method before
Difference between assert and verify in selenium web driver.
When an assert fails, the test will be aborted. Assert is best used when the
check value has to pass for the test to be able to continue to run log in.
Where if a verify fails, the test will continue executing and logging the failure.
Verify is best used to check non critical things. Like the presence of a headline
element.
"I want to find the location of ""b"" in the below code, how can I find out without
using xpath, name,
id, csslocator, index.<div>
<Button>a</button>
<Button>b</button>
<Button>c</button>
</div>
driver.findElement(By.xpath("//*[contains(text(),'b')]")).click(); or
//div/button[contains(text(),'b']
How to do Applet testing using selenium?
// selenium setup
selenium = new DefaultJavaSelenium("localhost",4444, browserString , url);
selenium.start();
selenium.open(url);
// get the appletfixure to control fest JAppletFixture
AppletFixture dialog = selenium.applet(LIST_APPLET_ID)
// fest similar API for autmation testing
dialog.comboBox("domain").select("Users");
dialog.textBox("username").enterText("alex.ruiz");
dialog.button("ok").click();
Name 5 different exceptions you had in selenium web driver and mention what
instance you got it and how do you resolve it?
WebDriverException
NoAlertPresentException
NoSuchWindowException
NoSuchElementException
TimeoutException
How do you manage the code versions in your project?
Using SVN or other versioning tools
Latest version of Firefox and selenium in market and the version on which you are
testing ?
FF Latest version till Dec,2013 for windows7,64 bit :26.0.I use FF 25.0.1 (ur ans.
may differ)
Selenium web driver latest version till dec,2013- 2.39.0 I use selenium 2.37 see
latest at
How to know all the methods supported in web driver and its syntax.
In Org.openqa.selenium package, web driver interface has all the main methods
that can be used in Selenium Web driver
How do you create html test report from your test script?
I would see below 3 ways:
Junit: with the help of ANT.
TestNG: using inbuilt default.html to get the HTML report. Also XLST reports from
ANT,
Selenium, TestNG combination.
Using our own customized reports using XSL jar for converting XML content to
HTML.
List the browsers, OS supported by the Selenium
Windows Linux Mac
IE Y NA NA
FF Y Y Y
Safari Y N Y
Opera Y Y Y
Chrome Y Y Y
Can you explain Selenium Mobile Automation?
import junit.framework.TestCase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;
public class OneTest extends TestCase {
public void testGoogle() throws Exception {
WebDriver driver = new AndroidDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
What mobile devices it may Support?
Selenium Web driver supports all the mobile devices operating on Android, IOS
operating Systems
Android for phones and tablets (devices & emulators)
iOS for phones (devices & emulators) and for tablets (devices & emulators)
What is the difference between single and double slash in Xpath?
/
It starts selection from the document node
It Allows you to create 'absolute' path expressions e.g /html/body/p matches all
the paragraph elements
//
It starts selection matching anywhere in the document
It Allows you to create 'relative' path expressions e.g//p matches all the
paragraph elements
What are the test types supported by Selenium?
Selenium supports UI and functional testing. As well it can support performance
testing for reasonable load using selenium grid.