Selenium Interview Questions
Selenium Interview Questions
Answer :
Selenium WebDriver software testing tool Is well designed object oriented API which Is developed to automate
web and mobile applications testing process. WebDriver API Is bigger than Selenium RC but It's Architecture Is
simple and easy to understand compared Selenium RC API.
We can automate our web application's software testing process using selenium webdriver.
We can say it is advanced version of selenium RC software testing tool because some limitations of selenium RC
has been overcome In selenium WebDriver software testing tool.
WebDriver Is designed to provide better support for dynamic changing pages. Example : Web page elements of
software web application is changing without reloading the page. In this case WebDriver works better.
Selenium Webdriver software testing tool Is more faster that Selenium RC software testing tool as It Is
directly Interacting with web browsers and mimic the behavior of a real user. Example : User clicks on button of
web page or moving mouse on main menu to get the sub menu list. WebDriver works Same.
All popular browser vendors are active participants In selenium WebDriver's development and all of them have
their own engineers team to Improve this framework.
You can Include answers of Question 2, Question 3, Question 4 and Question 5 In answer of this question If
Interviewer need more detail on selenium webdriver.
Answer : Selenium WebDriver API has a many different drivers to test your web application In different browsers.
List of Webdriver browser drivers are as bellow.
Answer : We can get support of mobile software application testing using Selenium webdriver. Selenium
WebDriver supports bellow given drivers to test mobile application.
AndroidDriver
OperaMobileDriver
IPhoneDriver
Answer : Selenium WebDriver Is very wast API and It support many different languages to write test cases for
your software web application. List of WebDriver supported languages are as bellow.
Java
C#
Python
Ruby
Perl
PHP
CSSSelector Locator
ClassName Locator
ID Locator
Name Locator
LinkText Locator
PartialLinkText Locator
TagName Locator
1. Selenium Projects : selenium interviewer may wants to know your knowledge on different selenium projects.
Selenium is not a single project. There are multiple selenium projects like Selenium IDE, Selenium RC(Remote
Control), Selenium WebDriver and Selenium Grid. All these projects are developed for web application's testing
purpose.
2. Selenium IDE is Limited version : Selenium IDE(Firefox Add-on) is record and playback tool. You can automate
simple web application scenarios(Example : Form submission, Navigation, etc..) using selenium IDE. But if you
wants to automate complex scenarios then it will be hard to automate it using selenium IDE. In this case, You can
use selenium RC or selenium webdriver.
3. Selenium Open-source : All the selenium projects are open-source so you can use any of them in free as per
your requirement.
4. No built-in IDE : Commercial automation tools like QTP and TestComplete have it's own IDE(Integrated
development Environment) to write automation test scripts. But selenium do not have it's own IDE. So it relies on
other IDEs like Eclipse(Java), Visual Studio(C#), etc.
5. Be master in programming : To be good tester in selenium and work with giant companies, You must have
strong knowledge of any one programming language. You can choose language as per your interest. So i am
suggesting you to be master in your selected language before learning selenium. Interviewer will ask you 60%
programming language questions and 40% selenium interview questions.
6. What is test automation in software testing : Selenium interviewer may ask you this question. In software
testing, Test automation is process of testing software application automatically using special software. It will
control test cases execution it self, compare expected and actual test results and provide test result reports.
Save time and money : Automation testing will save time and money as we need to create test automation scripts
just once and then we can run it whenever required. Automation test scripts will run itself so required very less
human efforts compared to manual testing. Also you can test your application in different browsers using same
test script so it will decrease your rework.
Improve testing accuracy : Sometimes human can make mistake but machine can't. Once you record script in
correct way, tool will run it every time as expected so it will improve your testing accuracy.
Test Coverage : As your all test cases are scripted so all the test cases will be executed in each test cycle on all
browsers. So it will improve your test coverage.
Selenium support multiple languages to create test scripts so you can choose your preferred language.
Selenium allow us to integrate other open-source unit testing frameworks like TestNG, JUnit, NUnit.
Using selenium Grid, We can run automation tests simultaneously on different machines, OS and browsers.
Able to create frameworks as per your requirement like Keyword Driven, Data driven and Hybrid etc.
We can integrate selenium with maven. Maven is helpful to compile source code, set dependencies so that it will
download required files automatically.
Also we can integrate Jenkins or Hudson with selenium for continuous integration.
It is not only testing tool but if you have repetitive web-based tasks then you can use selenium to perform those
tasks automatically.
Fast Test Execution : Manual software testing process Is time consuming. Automation tests are faster and takes
less time to execute tests compared to manual test execution.
Re-usability Of Test Cases : You need to prepare automation test cases only one time. Then you can use same
test cases for all upcoming version release of software application. However you need to modify your test cases If
there Is any flow change of business logic changes In software. But It Is less time consuming.
Testing Cost Reduction : You have to put human efforts only one time to automate your software test process.
Latter on automation tool will work for you at place of human resource.
Better Test Coverage In Each Version Release: You have to Implement test scenarios only once In your
automation test cases. Latter on you can execute same test cases In all upcoming release. So each scenarios will
be tested In every version release.
Easy For Compatibility Testing : It Is easy to run same tests In combination of different OS and browser
environments using automation tools.
Answer : No. WebDriver do not have any record and playback facility. But you can record your tests In one of the
selenium version called Selenium IDE and then you can export your recorded tests In webdriver compatible
format as per your preferred language.
8 : Which Operating systems support Selenium WebDriver?
Answer : At present, Mainly bellow given operating systems support Selenium WebDriver.
Apple OS X
9 : Selenium WebDriver Is Paid Or Open Source Tool? Why you prefer to use It?
Answer : All versions of selenium software testing tool are open source. You can use any version of selenium In
free of charge.
I choose to use It because
Open Source.
Multi-OS support.
Multi types of locators support. So If one not works, We can use another type.
Many testers are using selenium WebDriver to automate their testing process. So getting solution of any complex
Issue very easily on Internet.
Continues support from WebDriver's development team to Improve the API and resolve current Issues.
TestNG
Selenium WebDriver Latest Job Interview Questions With Answers Part-3
11 : Can you tell me the syntax to open/launch Firefox browser In WebDriver software testing tool?
Answer : We can open new Mozilla Firefox browser Instance using bellow given syntax In WebDriver software
testing tool.
Answer : In Selenium WebDriver software testing tool, XPath is used to locate the elements. Using XPath, We can
navigate through elements and attributes In an XML document to locate software webpage elements like
buttons, text box, links, Images etc..
13 : Which tool you are using to find the XPath of any element?
Answer : I am using Mozilla Firefox AddOns FireBug and FirePath to find the XPath of software web elements.
Answer :
Absolute XPath : Absolute XPath Is the full path starting from root node and ends with desired descendant
element's node. It will start using single forward slash(/) as bellow.
Example Of Absolute XPath :
/html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div/div/div[1]/div/div/div/div[1]/
div[2]/form/table/tbody/tr[1]/td/input
Relative XPath : Instead of starting from root node, Relative XPath starts from any In between node or current
element's node(last node of element). It will start using double forward slash(//) as bellow.
Example Of Relative XPath :
//input[@id='Resultbox']
Alternative 1 : Look for any other attribute which Is not changing every time In that div node like name, class etc.
So If this div node has class attribute then we can write xpath as bellow.
//div[@class='post-body entry-content']/div[1]/form[1]/input[1]
Alternative 2 : You can use absolute xpath(full xpath) where you not need to give any attribute names In xpath.
/html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div/div/div[1]/div/div/div/div[1]/
div[2]/div[1]/form[1]/input[1]
Alternative 3 : Use starts-with function. In this xpath's ID attribute, "post-body-" part remain same every time. So
you can use xpath as bellow.
//div[starts-with(@id,'post-body-')]/div[1]/form[1]/input[1]
Alternative 4 : Use contains function. Same way you can use contains function as bellow.
div[contains(@id,'post-body-')]/div[1]/form[1]/input[1]
Job Interview Questions For Selenium WebDriver With Answers Part-4
Answer : To press ENTER key using selenium WebDriver software automation tool, We need to use
selenium Enum Keys with Its constant ENTER as bellow.
driver.findElement(By.xpath("//input[@id='gbqfq']")).sendKeys(Keys.ENTER);
Answer : There are two types of waits available In selenium WebDriver software automation testing tool.
Implicit Wait
Explicit Wait
Answer : Sometimes, Elements are taking time to be appear on software web application page. Using Implicit
wait In webdriver software testing test case, We can poll the DOM for certain amount of time when some
element or elements are not available Immediately on webpage.
Implicit Wait Example :
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
If you will write above syntax In your test, Your WebDriver test will wait 10 seconds for appearing element on
page.
Answer : Using explicit wait code In selenium webdriver software automation testing tool, You can define to wait
for a certain condition to occur before proceeding further test code execution.
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='gbqfq']")));
Above code will wait for 20 seconds for targeted element to be displayed and enabled or we can say clickable.
20 : I wants to pause my test execution for fix 10 seconds at specific point. How can I do It?
Answer : You can use java.lang.Thread.sleep(long milliseconds) method to pause the software test execution for
specific time. If you wants to pause your test execution for 10 seconds then you can use bellow given syntax In
your test.
Thread.sleep(10000);
Answer :
When browser loaded In Selenium RC, It ‘injected’ javascript functions into the browser and then It Is using
javascript to drive the browser for software application under test.
Answer : Selenium webdriver software testing tool works like real user Interacting with software web page and Its
elements. It Is using each browser's native support to make direct calls with browser for your software
application under test. There Is not any Intermediate thing In selenium webdriver to Interact with web browsers.
Answer : It depends. If you are using only selenium webdriver API to run your tests and you are running your all
your tests on same machine then you do not need selenium server because In this case, webdriver can directly
Interact with browser using browser's native support.
You need selenium server with webdriver when you have to perform bellow given operations with selenium
webdriver.
When you are using remote or virtual machine to run webdriver tests for software web application and that
machine have specific browser version that is not on your current machine.
When you are using selenium-grid to distribute your webdriver's test execution on different remote or virtual
machines.
24 : Bellow given syntax will work to navigate to specified URL In WebDriver? Why?
driver.get("www.google.com");
Answer : No. It will not work and show you an exception like : "Exception in thread "main"
org.openqa.selenium.WebDriverException: f.QueryInterface is not a function" when you run your test.
You need to provide http:// protocol with URL In driver.get method as bellow.
driver.get("http://www.google.com");
25 : Tell me a reason behind bellow given WebDriver exception and how will you resolve It?
First of all I will check that I have placed Implicit wait code In my test or not. If you have not placed Implicit
timeout In your test and any element Is taking some time to appear on page then you can get this exception. So I
will add bellow given line at beginning of my test case code to wait for 15 seconds for element to be present on
page. In 70% cases, this step will resolved Issue.
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
Another reason behind this Issue Is element's ID Is generated dynamically every time when reloading the page. If
I have used element's ID as an element locator or used It In xpath to locate the element then I need to verify that
ID of element remains same every time or It Is changing? If It Is changing every time then I have to use alternative
element locating method. In 20% cases, This step will resolve your Issue.
If Implicit wait Is already added and element locator Is fine then you need to verify that how much time
It(element) Is taking to appear on page. If It Is taking more than 15 seconds then you have to put explicit wait
condition with 20 or more seconds wait period as bellow. In 5 to 10% cases, This step will resolve your Issue.
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#submitButton")))
Latest Selenium Interview Questions With Answers Part 6
Answer : No. This Is the biggest disadvantage of selenium WebDriver API. We can automate only web and mobile
software application's testing using selenium WebDriver.
27 : Can you tell me the alternative driver.get() method to open URL In browser?
Answer : We can use anyone from bellow given two methods to open URL In web browser In selenium webdriver
software testing tool.
driver.get()
driver.navigate().to()
Answer : Main and mostly used functions of both methods are as bellow.
driver.get()
driver.get() method Is generally used for Open URL of software web application.
driver.navigate()
driver.navigate() method Is generally used for navigate to URL of software web application, navigate back,
navigate forward, refresh the page.
It will just navigate to the page but wait not wait till the whole page gets loaded.
Answer : No. WebDriver do not have any built In object repository till now. But yes, I am using java .properties file
In my framework to store all required element objects In my tests.
30 : Can you tell me syntax to set browser window size to 800(Width) X 600(Height)?
Answer : We can set browser window size using setSize method of selenium webdriver software testing tool. To
set size at 800 X 600, Use bellow given syntax In your test case.
driver.manage().window().setSize(new Dimension(500,500));
Selenium WebDriver Questions Part - 7
31 : Can you tell me the names of different projects of selenium software automation testing tool?
Answer : At present, Selenium software automation testing tool has four different projects as bellow.
Selenium IDE : It Is Firefox add-on which allows you to record and playback your software web application's tests
In Firefox browser.
Selenium RC : It Is software web application automation tool which allows you to write your tests In many
different programming languages.
Selenium WebDriver : It Is well designed object oriented API developed to automate web and mobile software
application testing process. You can write your tests In different languages too In selenium webdriver.
Selenium Grid : Grid allows you to execute your tests In parallel by distributing them on different machines
having different browser/OS combinations.
32 : I wants to use java language to create tests with Selenium WebDriver. Can you tell me how to get latest
version of WebDriver?
Answer : You can download language specific latest released client drivers for selenium WebDriver software
testing tool at http://docs.seleniumhq.org official website. For java language, You will get bunch of jar files In zip
folder. And then you can add all those jar files In your project's java build path as a referenced libraries to get
support of webdriver API.
33 : Can you tell me the usage of "submit" method In selenium WebDriver?
Answer : We can use submit method to submit the forms In selenium WebDriver software automation testing
tool. Example : Submitting registration form, submitting LogIn form, submitting Contact Us form ect.. After filling
all required fields, We can call submit method to submit the form.
34 : Do you have faced any Issue with "submit" method any time?
Answer : Yes, I have faced Issue like submit method was not working to submit the form. In this case, Submit
button of form was located outside the opening <form> and closing </form> tags. In this case submit method will
not works to submit the form.
Also If submit button Is located Inside opening <form> and closing </form> tags but that button's type tag's
attribute Isn't submit then submit method will not work. It(type tag's attribute) should be always submit.
35 : What Is the syntax to type value In prompt dialog box's Input field using selenium WebDriver?
Answer : Prompt dialog Is just like confirmation alert dialog but with option of Input text box as bellow.
To Input value In that text box of prompt dialog, You can use bellow given syntax.
driver.switchTo().alert().sendKeys("Jhon");
36 : When I am running software web application's tests In Firefox Browser using selenium webdriver, It Is not
showing me any bookmarks, addons, saved passwords etc. In that browser. Do you know why?
Answer : Yes. It Is because all those bookmarks, addons, passwords etc.. are saved In your regular browser's
profile folder so when you launch browser manually, It will use existing profile settings so
It will show you all those stuffs. But when you run your software web application's tests In selenium webdriver, It
Is opening new browser Instance with blank/new profile. So It will not show you bookmarks and all those things
In that browser Instance.
You can create custom firefox profile and then you can use It In selenium webdriver test. In your custom profile,
you can set all required bookmarks, addons etc
HtmlUnit Driver
Firefox Driver
38 : What Is Ajax?
Answer : Asynchronous JavaScript and XML Is full form of AJAX which Is used for creating dynamic web pages very
fast for software web applications. Using ajax, We can update page behind the scene by exchanging small
amounts of data with server asynchronously. That means, Using ajax we can update page data Without reloading
page.
Answer : Generally we are using Implicit wait In selenium WebDriver software automation tests to wait for some
element to be present on page. But Ajax call can not be handled using only Implicit wait In your test because page
not get reloaded when ajax call sent and received from server and we can not assume how much time It will take
to receive ajax call from server.
To handle ajax call In selenium WebDriver software automation tests, We needs to use webdriver's FluentWait
method or Explicit Waits which can wait for specific amount of time with specific condition.
40 : On Google search page, I wants to search for some words without clicking on Google Search button. Is It
possible In WebDriver? How?
Answer : Yes we can do It using WebDriver sendKeys method where we do not need to use Google Search button.
Syntax Is as bellow.
driver.findElement(By.xpath("//input[@id='gbqfq']")).sendKeys("Search Syntax",Keys.ENTER);
In above syntax, //input[@id='gbqfq'] Is xPath of Google search text field. First It will enter "Search Syntax" text In
text box and then It will press Enter key on same text box to search for words on Google.
Selenium WebDriver Job Interview Questions Part - 9
41 : What kind of software testings are possible using selenium WebDriver? We can use It for any other
purpose except testing activity?
Answer : Generally we are using selenium WebDriver for functional and regression testing of software web
applications.
42 : Give me any five different xPath syntax to locate bellow given Input element.
Answer : Five xPath syntax for above element of software web application page are as bellow.
//input[@id='fk-top-search-box']
//input[contains(@name,'q')]
//input[starts-with(@class, "search-bar-text")]
//input[@id='fk-top-search-box' or @name='q']
Answer : Two main disadvantage of xPath locator as compared to cssSelector locator are as bellow.
xPath which works In one browser may not work In other browser for same page of software web application
because some browsers (Ex. IE) reads only Lower-cased tag name and Attribute Name. So If used It In upper case
then It will work In Firefox browser but will not work In IE browser. Every browser reads xPath In different way. In
sort, do not use xPath locators In your test cases of software web application If you have to perform cross
browser testing using selenium WebDriver software testing tool.
44 : Why xPath locator Is much more popular than all other locator types In WebDriver?
Answer : xPath locators are so much popular In selenium webdriver test case development because
There are many functions to build xPath In different ways like contains, starts-with etc.. So If one Is not possible
you will have always another option to build xPath of any element.
Presently many tools and add-ons are available to find xpath of any element.
45 : Give me WebDriver's API name using which we can perform drag and drop operation.
Answer : That API's name Is Advanced User Interactions API using which we can perform drag and drop operation
on page of software web application. Same API can help us to perform some other operations too like
moveToElement, doubleClick, clickAndHold, moveToElement, etc
Interview Questions For Selenium WebDriver Part 10
46 : Can we perform drag and drop operation In Selenium WebDriver? Tell me a syntax to drag X element and
drop It On Y element.
Answer : Yes, We can perform drag and drop operation using selenium webdriver software testing
tool's Advanced User Interactions API. Syntax Is like below.
47 : Do you have faced any technical challenges with Selenium WebDriver software test automation?
Answer : Yes, I have faced below given technical challenges during selenium webdriver test cases development
and running for software web application.
Sometimes (Not always), Some elements like text box, buttons etc. are taking more time(more than given Implicit
wait time) to appear on page of software web application or to get enabled on page. In such situation, If I have
used only Implicit wait then my test case can run fine on first run but It may fail to find element on second run. So
we need provide special treatment for such elements so that webdriver script wait for element to be present or
get enabled on page of software web application during test execution. We can use Explicit wait to handle this
situation.
Handling dynamic changing ID to locate element Is tricky. If element's ID Is changing every time when you reload
the software web application page and you have to use that ID In XPath to locate element then you have to use
functions like starts-with(@id,'post-body-') or contains(@id,'post-body-') In XPath..
Clicking on sub menus which are getting rendered on mouse hover of main menu Is some what tricky. You need
to use webdriver's Actions class to perform mouse hover operation.
If you have to execute your test cases In multiple browsers then one test case can run successfully In Firefox
browser but same test case may fail In IE browser due to the timing related Issues (nosuchelement exception)
because test execution In Firefox browser Is faster than IE browser. You can resolve this Issue by Increasing
Implicit wait time when you run your test In IE browser.
Above Issue can arise due to the unsupported XPath In IE browser. In this case, You need to (ID, Name,
CSSSelector etc.) locate element.
Handling JQuery elements like moving pricing slider, date picker, drag and drop etc.. Is tricky. You should have
knowledge of webdriver's Advanced User Interactions API to perform all these actions.
Working with multiple Windows, Frames, and some tasks like Extracting data from web table, Extracting data
from dynamic web table, Extracting all Links from page, Extracting all text box from page are also tricky and time
consuming during test case preparation.
There Is not any direct command to upload or download files from web page using selenium webdriver. For
downloading files usign selenium webdriver, You need to create and set Firefox browser profile with webdriver
test case.
Webdriver do not have any built In object repository facility. You can do It using java .
Webdriver do not have any built In framework or facility using which we can achieve below given tasks directly :
1. Capturing screenshots, 2. generating test execution log, 3. reading data from files, 4. Generating test result
reports, Manage test case execution sequence. To achieve all these tasks, We have to use external services with
webdriver like Log4J to generate log, Apache POI API to read data from excel files, Testng XSLT reports to
generate test result reports. TestNG to manage test case execution, .properties file to create object repository. All
these tasks are very time consuming.I have described how to create data driven framework step by step for
selenium webdriver. That framework contains all above functionality.
You can share other webdriver technical challenges which you have faced by commenting below so that your
experience can help to others too.
48 : Can you tell me a syntax to close current webdriver Instance and to close all opened webdriver Instances?
Answer :
Yes, To close current WebDriver Instance, We can use Close() method as bellow.
driver.close();
If there are opened multiple webdriver Instances and wants to close all of them then we can use webdriver's
quit() method as bellow in software automation test.
driver.quit();
49 : Is It possible to execute javascript directly during software test execution? If Yes then tell me how to
generate alert by executing javascript In webdriver script?
Answer :
Yes, we can execute javascript during webdriver software test execution. To generate alert, You can write bellow
given code In your script.
JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("alert('Javascript Executed.');");
50 : Give me a syntax to read javascript alert message string, clicking on OK button and clicking on Cancel
button.
Answer :
We can read alert message string as bellow.
String alrtmsg = driver.switchTo().alert().getText();
Answer :
1. Bitmap comparison Is not possible using selenium webdriver software testing tool.
2. Automating captcha Is not possible. (Few peoples says we can automate captcha but I am telling you If you can
automate any captcha then It Is not a captcha).
3. We can not read bar code using selenium webdriver software testing tool.
52 : What Is JUnit?
Answer : Java software developers use JUnit as unit testing framework to write repeatable tests for java
programming language. It Is very simple and open source framework and we can use It In selenium webdriver
test scripts creation to manage them In well manner
Selenium WebDriver With JUnit Interview Questions With Answers Part 12
Answer : Current latest version of JUnit Is 4.12-beta-2. This can change In future. To check latest released version
of JUnit, You can Visit JUnit Official WebSite.
@Test : @Test annotation Is useful to Identify method as a Test method from software automation test script.
@Before : @Before annotation method will be executed before each and every @Test method.
@After : @After annotation method will be executed after each and every @Test method.
@BeforeClass : @BeforeClass annotation method will be executed before all @Test methods In a class(Means
before first @Test method).
@AfterClass : @AfterClass annotation method will be executed after all @Test method In a class(Means after last
@Test method).
@Test(timeout=1000) : You can set @Test method execution timeout. This @Test method fails Immediately
when Its execution time cross 1000 milliseconds.
55 : Write sample JUnit @Test method that passes when expected ArithmeticException thrown.
@Test(expected = ArithmeticException.class)
int i = 5/0;
56 : Write sample JUnit @Test method that fails when unexpected ArithmeticException thrown.
@Test
int i = 5/0;
}
57 : What are the advantages of TestNG over JUnit.
JUnit Is unit software testing framework. So It helps software developers to create and run unit test cases very
easily.
There are many different annotations available In JUnit. Using all those annotations, we can Identify and
configure webdriver software test case very easily.
JUnit supports many different assertions using which we can compare webdriver software automation test's
expected and actual result.
We can create test suite for multiple test cases to run all of them In one go using JUnit.
We can generate webdriver test execution HTML reports using JUnit. VIEW EXAMPLE.
assertEquals
assertFalse
assertTrue
assertNull
assertNotNull
assertSame
assertNotSame
assertArrayEquals
60 : How to create and run JUnit test suite for selenium WebDriver?
Answer : For creating JUnit software test suite, we have to create test cases class files and one separate test suite
file. Then we can write syntax like bellow In test suite file to run test suite.
@RunWith(Suite.class)
In above example, junittest1.class and junittest2.class are test case class names.
Answer : In selenium webdriver software test automation, We need to assert Boolean conditions true and false.
We can assert both these conditions using assertTrue and assertFalse JUnit assertions.
62 : Can you give me example of JUnit assertEquals assertion?
Answer : Example of JUnit assertEquals assertion Is as bellow. It assert that values of actTotal and expTotal are
equal or not.
int actTotal = 0;
assertEquals(actTotal, expTotal);
}
Selenium WebDriver with TestNG Interview Questions With Answers Part 14
63 : What Is TestNG?
Answer : TestNG Is Open Source(Freeware) framework which Is Inspired from NUnit and JUnit with Introducing
few new features and functionality compared to NUnit and JUnit to make It easy to use and more powerful.
We can use TestNg with selenium webdriver software testing tool to configure and run test cases very easily, easy
to understand, read and manage test cases, and to generate HTML or XSLT test reports.
Answer : TestNG has many major features like support of @DataProvider annotation to perform data driven
testing on software web application, can set test case execution dependency, test case grouping, generate HTML
and XSLT test execution report for software web application etc
65 : Describe the similarities and difference between JUnit and TestNG unit testing frameworks.
Answer : You can find all the similarities and difference between JUnit and TestNG framework on THIS PAGE.
66 : How to Install TestNG In Eclipse? How do you verify that TestNg Is Installed properly In Eclipse?
Answer : To Install TestNG software unit testing framework In Eclipse, We have to follow steps as described on
THIS PAGE.
Answer : TestNG supports many different annotations to configure Selenium WebDriver software automation
test
Answer : In selenium WebDriver software testing tool, We are using testng.xml file to configure our whole test
suite In single file. Few of the tasks which we can specify In testng.xml file are as bellow.
We can define software testing test suite using set of test cases to run them from single place.
Can Include or exclude test methods from software web application's test execution.
Answer : We can define parameter In testng.xml file using syntax like bellow.
Here, name attribute defines parameter name and value defines value of that parameter. Then we can use that
parameter In selenium webdriver software automation test case using bellow given syntax.
@Parameters ({"browser"})
70 : I have a test case with two @Test methods. I wants to exclude one @Test method from execution. Can I do
It? How?
Answer : Yes you need to specify @Test method exclusion In testng.xml file as bellow.
<classes>
<methods>
</methods>
</class>
</classes>
</test>
</suite>
You need to provide @Test method name In exclude tag to exclude It from execution.
Answer : You can use bellow given syntax Inside @Test method to skip It from test execution.
It will throw skip exception and @Test method will be sipped Immediately from execution. You can VIEW FULL
EXAMPLE on how to skip @Test method from execution.
72 : Arrange bellow give testng.xml tags from parent to child.
<test>
<suite>
<class>
</methods>
</classes>
<suite>
<test>
</classes>
<class>
</methods>
TestNG Interview Questions And Answers For Selenium WebDriver Part 16
Answer : In your software web application's test case, you can set priority for TestNG @Test annotated methods
as bellow.
@Test(priority=0)
Using priority, We can control @Test method execution manner as per our requirement. That means @Test
method with priority = 0 will be executed 1st and @Test method with priority = 1 will be executed 2nd and so on.
VIEW PRACTICAL EXAMPLE to know how to use It.
74 : Tell me any 5 assertions of TestNG which we can use In selenium webdriver software testing tool.
Answer : There are many different assertions available In TestNG but generally I am using bellow given assertions
In my test cases.
Answer : Using TestNG soft assertion, We can continue our test execution even if assertion fails. That means on
failure of soft assertion, remaining part of @Test method will be executed and assertion failure will be reported
at the end of @Test method. VIEW PRACTICAL EXAMPLE.
76 : How to write regular expression In testng.xml file to search @Test methods containing "product" keyword.
Answer : Regular expression to find @Test methods containing keyword "product" Is as bellow In selenium
webdriver software testing tool.
<methods>
<include name=".*product.*"/>
</methods>
77 : Which time unit we provide In time test? minutes? seconds? milliseconds? or hours? Give Example.
Answer : Time unit we provide on @Test method level or test suite level Is In milliseconds.
List Of Interview Questions For Selenium WebDriver Part 17
78 : What Is the syntax to get value from text box and store It In variable.
Answer : Most of the time, String In text box will be stored as value. So we need to access value
attribute(getAttribute) of that text box as shown In bellow example.
Answer : findElement Is useful to locate and return single element from page of software web application
while findElements Is useful to locate and return multiple elements from software web page.
80 : Tell me looks like XPath of sibling Input element which Is after Div in the DOM.
//div/following-sibling::input
81 : Tell me looks like CSSSelector path of sibling Input element which Is after Div in the DOM.
css=div + input
Answer : In general software term, Parallelism means executing two part of software program simultaneously or
executing software program simultaneously or we can say multithreaded or parallel mode. TestNG has same
feature using which we can start multiple threads simultaneously In parallel mode and test methods will be
executed In them
Interview Questions With Detailed Answers On Selenium Part 18
Your software test execution time will be reduced as multiple tests will be executed simultaneously.
84 : I wants to run test cases/classes In parallel. Using which attribute and value I can do It?
Answer : You have to use parallel = classes attribute In testng.xml to run software web app tests parallel
Answer : Dependency Is very good feature of testng using which we can set software test method as dependent
test method of any other single or multiple or group of test methods. That means depends-on method will be
executed first and then dependent test method will be executed. If depends-on software test method will fail
then execution of dependent test method will be skipped automatically. TestNG dependency feature will works
only If depends-on test method Is part of same class or part of Inherited base class
86 : What Is the syntax to set test method dependency on multiple test methods.
Answer : We can set test method's dependency on multiple test methods as bellow.
@Test(dependsOnMethods={"Login","checkMail"})
}
Above test method Is depends on Login and checkMail test methods.
Answer : We can use attribute enabled = false with @Test annotation to set test method disabled. Syntax Is as
bellow.
@Test(enabled = false)
}
Disabled software test methods will be excluded automatically during execution.
WebDriver Interview Questions With Answers Part 19
88 : In XPath, I wants to do partial match on attribute value from beginning. Tell me two functions using which
I can do It.
Answer : We can use bellow given two functions with XPath to find element for software web page using
attribute value from beginning.
contains()
starts-with()
89 : I have used findElements In my software test case. It Is returning NoSuchElementException when not
element found. Correct me If I am wrong.
Answer : It Is Incorrect. findElements will never return NoSuchElementException. It will return just an empty list.
90 : My Firefox browser Is not Installed at usual place. How can I tell FirefoxDriver to use It?
Answer : If Firefox browsers Is Installed at some different place than the usual place then you needs to provide
the actual path of Firefox.exe file as bellow.
System.setProperty("webdriver.firefox.bin","C:\\Program Files\\Mozilla Firefox\\Firefox.exe");
91 : How to create custom firefox profile and how to use It In selenium webdriver software test?
Answer : You can view detailed answer for firefox custom profile.
92 : What versions of Internet Explorer are supported by selenium WebDriver software testing tool?
Answer : Till date, Selenium WebDriver software testing tool supports IE 6, 7, 8, 9, 10 and 11 with appropriate
combinations of Windows 7, Vista or XP.
Selenium Advanced Interview Questions With Detailed Answers Part 20
93 : Tell me the class name using which we can generate Action chain.
Answer : The WebDriver class name Using which we can generate Action chain Is "Actions". VIEW USAGE OF
ACTIONS CLASS with practical example on how to generate series of actions to drag and drop element of software
web application.
94 : Do you know method name using which we can builds up the actions chain?
Answer : Few of the examples are bellow where can use actions class to perform operations In software web
application.
Answer : We can use selenium webdriver TakesScreenshot method to capture screenshot. Java File class will be
used to store screenshot In your system's local drive.
97 : Selenium WebDriver has any built In method using which we can read data from excel file?
Answer : No, Selenium webdriver software testing tool do not have any built In functionality using which we can
read data from excel file.
WebDriver Latest Questions Part 21
98 : Do you know any external API name using which we can read data from excel file?
Answer :
We can use jxl API (Java Excel API) to read data from excel file.
We can use one more powerful API known as Apache POI API to read and write data In excel file. I have created
data driven framework using Apache POI API.
99 : Tell me any 5 webdriver common exceptions which you faced during software test case execution.
TimeoutException - This exception will be thrown when command execution does not complete In given time.
NoSuchElementException - WebDriver software testing tool will throw this exception when element could not be
found on page of software web application.
NoAlertPresentException - This exception will be generated when webdriver ties to switch to alert popup but
there Is not any alert present on page.
ElementNotVisibleException - Thrown when webdriver Is not able to Interact with element which Is available In
DOM but It Is hidden.
StaleElementReferenceException
100 : Tell me different ways to type text In text box In selenium software test.
Answer : We can type text In text box of software web application page using bellow given ways In selenium test.
2. Using JavascriptExecutor
((JavascriptExecutor)driver).executeScript("document.getElementById('fname').value='Using
JavascriptExecutor'");
robot.keyPress(KeyEvent.VK_U);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_N);
robot.keyPress(KeyEvent.VK_G);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_R);
robot.keyPress(KeyEvent.VK_O);
robot.keyPress(KeyEvent.VK_B);
robot.keyPress(KeyEvent.VK_O);
robot.keyPress(KeyEvent.VK_T);
Answer : We can check If element Is present or not on page of software we application using bellow given 2
simple ways.
1. Using .size() method
Boolean elePresent = driver.findElements( By.id("ID of element") ).size() != 0;
If above syntax return "false" means element Is not present on page and "true" means element Is present on
page.
2. Using .isEmpty() method
Boolean elePresent = driver.findElements(By.id("ID of element")).isEmpty();
If this returns "true" means element Is not present on page and "false" means element Is present on page.
Answer : Webdriver launch fresh browser Instance when we run software tests In Firefox browser using selenium
webdriver. Fresh browser Instance do not have any Installed add-ons, saved passwords, bookmarks and any other
user preferences. So we need to create custom profile of Firefox browser to get any of this thing In Webdriver
launched browser.
Selenium Latest Questions Part 22
103 : How to customize Firefox browser profile for webdriver software test?
You can create your desired firefox browser profile before running software automation test and then you can
use It In your selenium webdriver software test.
You can customize your firefox browser profile run time before launching webdriver's Firefox browser Instance.
Answer :
getAttribute() method Is useful to read software web app element's attribute value like id, name, type
etcgetText() method Is useful to read text from element or alert.
WebDriver : Webdriver Is an Interface or we can say software testing tool using which we can create automated
test cases for web application and then run on different browsers like IE, Google chrome, Firefox etc.. We can
create test cases In different languages.
Remote WebDriver : Remote WebDriver Is useful to run test cases In same machine or remote machines using
selenium Grid.
106 : I have total 200 test cases. I wants to execute only 20 test cases out of them. Can I do It In selenium
WebDriver? How?
Answer : Yes. If you are using TestNG with selenium webdriver software testing tool then you can do Is using
grouping approach. Create separate group for those 20 test cases and configure testng.xml file accordingly to run
only those 20 test cases.
Also If you are using data driven framework then you can configure It In excel file. You can configure such data
driven framework at your own.
107 : Can you tell me three different ways to refresh page. Do not use .refresh() method.
Answer : We can refresh browser In many different ways. Three of them are as bellow.
driver.get(driver.getCurrentUrl());
driver.navigate().to(driver.getCurrentUrl());
driver.findElement(By.xpath("//h1[@class='title']")).sendKeys(Keys.F5);
Latest Interview Questions On Selenium Advanced Usage Part 23
108 : I wants to pass parameter In software test case through testng.xml file. How can I do It?
Answer : You can use <parameter> node under <test> node In testng.xml file with parameter name and value.
Then you can use @Parameters annotation with parameter name In your test case of software web application.
109 : My page contains file upload field but I am not able to upload file using selenium webdriver software
testing tool. Is there any other way using which I can upload file In selenium test?
Answer : If you are not able to upload file using selenium webdriver then you can create file upload script In
AutoIT and then you can use It In selenium webdriver software test. You can refer bellow given articles to learn
more about It.
What Is AutoIT V3
Answer : We can use setSize function to set size of window and setPosition function to set position of browser
window.
111 : Is there any way to get size and position of browser window in selenium webdriver?
Answer : Yes.. We can get it using webdriver functions getSize and getPosition.
112 : I wants to scroll my software web application page by 300 pixel. Tell me how can i do it?
Answer : We can use javascript executor with window.scrollBy(x,y) to scroll page in x or y directions.