Anda di halaman 1dari 49

100 Best Selenium Job Interview

Questions & Answers


This article will be useful for all who are planning to get a testing or test automation
job. More than 100 most popular Questions & Answers from Selenium Job
Interviews have been compiled here.

1) What is Automation Testing?

Automation testing is a process in which software tools execute pre-scripted tests on


a software application before it is released into production. Special software is used
to control the test execution, actual outcomes and predicted outcomes comparison,
the test preconditions setting up, and other test control and test reporting functions.

2) What are the main advantages of Automation Testing?

Regression testing coverage, test engineer productivity, consistency in testing, test


cases reusability, reduced software maintenance cost, increased test effectiveness,
reduction of the test interval, reducing human-generated errors.

3) So, what is Selenium?

Selenium is a robust test automation suite designed in a way to support and


encourage automation testing of functional aspects of web-based applications and a
wide range of browsers and platforms.

4) What are the main advantages of Selenium?

 Selenium is a free and open source. You don't need to spend any licensing
cost to use it.
 Cross Browser compatibility (Firefox, Chrome, Internet Explorer, Safari etc.)
 Multiple programming languages (Java, C#, Ruby, Python, Pearl etc.) support
 Compatibility with the main platform (Windows, Mac OS, Linux etc.)
 Huge amount user base and helping communities
 Automation scripts creating ability for non-programmers as well as for
programmers
 Testing distribution support
 Regular and fresh repository developments

5) What Selenium components do you know?

Selenium is a suite of tools for automated web testing. It is composed of:


 Selenium IDE (Integrated Development Environment). It is a tool for
recording and playing back. It is a Firefox plugin.
 WebDriver and RC. It provides the APIs for a variety of languages like Java,
.NET, PHP, etc. They work with most of the browsers.
 Grid: you can distribute tests on multiple machines so that test can be run
parallel which helps cutting down the time required for running test suites in
the browser.

6) How many types of Webdriver APIs are available in Selenium?

The list of driver classes could be used for the browser automation.

 AndroidDriver,
 ChromeDriver,
 EventFiringWebDriver,
 FirefoxDriver,
 HtmlUnitDriver,
 InternetExplorerDriver,
 iPhoneDriver,
 iPhoneSimulatorDriver,
 RemoteWebDriver

7) Does the Selenium have any limitations?

Selenium supports only web based applications testing. So, here are the limitations
of it:

 Mobile applications cannot be tested using Selenium


 Desktop applications cannot be tested using Selenium
 Captcha and Bar code readers cannot be tested using Selenium
 User should use third-party tools like TestNG or jUnit to write test scripts
and generate reports
 Programming language knowledge is required to create robust scripts in
Selenium WebDriver

8) What is Selenium IDE?

Selenium IDE is a plug-in used to record and replay tests in Firefox browser. Scripts
may be automatically recorded and edited manually providing auto-completion
support and the ability to move commands around quickly.

9) What is Selenese?

Selenese is the language which is used to write test scripts in Selenium IDE.
10) What kinds of test types are supported by Selenium?

1. Functional Testing
2. Regression Testing
3. Sanity Testing
4. Smoke Testing
5. Responsive Testing
6. Cross Browser Testing
7. UI testing (black box)
8. Integration Testing

are supported by Selenium.

11) What are the different types of locators in Selenium?

The different types of locators in Selenium are ID, ClassName, Name, TagName,
LinkText, PartialLinkText, XPath, CSS Selector, DOM.

12) What automation tools could be used for post-release validation with
continuous integration?

Automation tools could be used for post-release validation with continuous


integration: CruiseCont, Hudson, Jenkins, Quick Build.

13) Explain the meaning of assertion in Selenium and what are the types of
assertion?

Assertion is used as a verification point. It verifies that the application state conforms
to the expectation. The types of assertion are “assert”, “verify” and “waifFor”.

14) Explain the difference between assert and verify commands?

Both of them check if the given condition is true or false. Unlike to "assert", "verify"
will not stop the test case execution if the test case fail.

15) What is a XPath?

XPath is a language that describes a way to locate and process items in Extensible
Markup Language (XML) documents by using an addressing syntax based on a path
through the document's logical structure or hierarchy.

16) What is an Absolute XPath?


Absolute XPath is the direct way to find the element. It has a disadvantage. XPath
gets failed if there are any changes made in the path of the element.
html/body/div[3]/div/div[1]/div/div/div[1]/div/input - Absolute XPath example.

17) What is a Relative XPath?

Relative XPath means that user can start from the middle of the HTML DOM
structure and no need to write long XPath. Example of Relative XPath -
//input[@id='email'].

18) What is the difference between single slash (/) and a double slash ( //) in
XPath?

A single slash (/) is used for creating XPaths with absolute paths beginning from the
root node.

Double slash (//) is used for creating relative XPath to start selection from anywhere
within the root node

19) How could the web element attributes be inspected in order to use them in
different locators?

Firebug is a Firefox plugin that provides various development tools for debugging
applications. From an automation perspective, Firebug is used specifically for
inspecting web-elements in order to use their attributes like id, class, name etc. in
different locators.

20) Give an example of the languages supported by WebDriver.

Java, C#, Python, and Ruby, are all supported directly by the development team.
There are also PHP and Perl WebDriver implementations.

21) How can we launch different browsers in Selenium WebDriver?

We should create an instance of a driver of a particular browser:

copy

1. WebDriver driver = new FirefoxDriver();

22) What the WebDriver supported Mobile Testing Drivers do you know?

Mobile Testing Drivers supported by the WebDriver are: AndroidDriver, IphoneDriver,


OperaMobileDriver.

23) Explain the fundamental difference between XPath and CSS selector.
Using CSS selector we can only move downwards in the document, using XPaths we
traverse up in the document.

24) How can you find if an element is displayed on the screen?

There are different methods, which help user to check the visibility of the web
elements: isDisplayed(), isEnabled(), isSelected(). These web elements can be
buttons, drop boxes, checkboxes, radio buttons, labels etc.

25) What is the difference between "type" and "typeAndWait" command?

If you need to type keyboard key values into a text field of the web application,
"type" command will be used. Another reason for its usage is selecting values of the
combo box. "typeAndWait" command is used when your typing is completed and
software web page start reloading.

26) How can the user get a text of a web element?

User can retrieve the text of the specified web element by using get command. It
doesn’t require any parameter but returns a string value.

copy

1. String Text = driver.findElement(By.id(“Some Text”)).getText()

is an example of it.

27) How a text written in a text field could be cleared?

A text written in a text field could be deleted by using the clear() method.

28) How to check a checkBox in Selenium?

The same click() method could be used for checking checkbox as well as for clicking
buttons or radio buttons.

29) How to verify if the checkbox/radio is checked or not?

isSelected() method is used to verify if the checkbox/radio is checked or not. An


example -

copy

1. driver.findElement(By.xpath("XPath of the checkbox/radio


button")).isSelected();
30) What is the alternate way to click on login button?

submit() method could be used as the alternate way to click on login button, but
only if attribute type=submit.

31) How to select a value in a dropdown?

WebDriver’s Select class is used to select value in the drop down.

copy

1. selectByVisibleText:
2. Select selectByVisibleText = new Select
(driver.findElement(By.id(“id_of_some_element”)));
3. selectByVisibleText.selectByVisibleText(“some_visible_text”);

32) Explain the difference between close and quit command.

If you need to close the current browser having focus driver.close() is used. If you
need to close all the browser instances driver.quit() is used.

33) What is the difference between setSpeed() and sleep() methods?

Both of these methods delay the speed of execution. The main difference between
them is setSpeed sets a speed while will apply delay time before every Selenium
operation takes place. thread.sleep() will set up wait only for once.

For Example:

 sleep(5000)- It will wait for 5 seconds. It is executed only once, where the
command is written.
 setSpeed("5000")- It also will wait for 5 seconds. It runs each command after
setSpeed delay by the number of milliseconds mentioned in set Speed.

34) What are the different types of navigation commands?

 navigate().back() command takes user back to the previous webpage in the


web browser’s history. An example: driver.navigate().back();
 navigate().forward() lets the user to navigate to the next web page with
reference to the browser’s history. An example: driver.navigate().forward();
 According to navigate().refresh() command user can refresh the current web
page there by reloading all the web elements. An example:
driver.navigate().refresh();
 User can launch a new web browser window and navigate to the specified URL
by executing navigate().to() An example:
copy

1. driver.navigate().to(“https:// thinkmobiles.com/”);

35) What is the difference between findElement () and findElements ()?

Both of them let user to find elements in the current web page matching to the
specified locator value. But if you use findElement(), only the first matching element
would be fetched. An example:

copy

1. WebElement element =
driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”))

If you use findElements(), the all matching elements would be fetched and stored in
the WebElements list. An example:

copy

1. List elementList =
driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));

36) Can Selenium handle Windows based pop-up?

Windows pop-ups cannot be handled by using Selenium. Because it supports only


web application testing.

37) How can we handle Web-based pop-up?

There are four methods of the effective Web-based pop-up handling:

 string getText() method returns the text displayed on the alert box
 void accept() method clicks on the “Ok” button as soon as the pop-up
window appears
 void dismiss() method clicks on the “Cancel” button as soon as the pop-up
window appears
 void sendKeys(String stringToSend) method enters the specified string
pattern into the alert box

38) Do you know a way to refresh browser by using Selenium?

The list of commands to refresh a page in Selenium:

 navigate().refresh()
 getCurrentUrl()
 navigate().to(driver.getCurrentUrl())
 sendKeys(Keys.F5)

39) How can we maximize browser window in Selenium?

copy

1. driver.manage().window().maximize(); //command is used to


maximize browser window in Selenium

40) How can we find the value of different attributes like name, class, value of
an element?

copy

1. getAttribute("{attributeName}") //method is used find the value


of different attributes of an element

41) Could cookies be deleted in Selenium?

copy

1. driver.manage().deleteAllCookies(); //command is used for


deleting all cookies

42) How to perform right click using Selenium WebDriver?

The next Actions class is used to perform right click:

copy

1. Actions act = new Actions(driver); // where driver is WebDriver


type
2. act.moveToElement(webElement).perform();
3. act.contextClick().perform();

43) How do perform drag and drop using Selenium WebDriver?

The next Actions class is used to perform drag and drop:

copy

1. Actions builder = new Actions(driver);


2. Action dragAndDrop = builder.clickAndHold(SourceElement)
3. moveToElement(TargetElement)
4. release(TargetElement)
5. build();
6. dragAndDrop.perform();

44) How to check if an element is visible on the page?


The return method type is logical. If it returns true then element is visible otherwise it
is not. isDisplayed() method could be used for it:

copy

1. driver.findElement(By.id(“id_of_element”)).isDisplayed();

45) How to check if a button is enabled on the page?

isEnabled() method could be used for it:

copy

1. driver.findElement(By.id(“id_of_element”)).isEnabled();

46) What kind of mouse actions can be performed in Selenium?

Selenium supports different mouse actions, such as:

 click(WebElement element)
 contextClick(WebElement element)
 doubleClick(WebElement element)
 mouseUp(WebElement element)
 mouseDown(WebElement element)
 mouseMove(WebElement element)
 mouseMove(WebElement element, long xOffset, long yOffset)

47) Can you write the code to double click an element in Selenium?

Code to double click an element in Selenium:

copy

1. Actions action = new Actions(driver);


2. WebElement element=driver.findElement(By.id("elementId"));
3. action.doubleClick(element).perform();

48) How to mouse hover an element in Selenium?

Code to mouse hover over an element in Selenium:

copy

1. Actions action = new Actions(driver);


2. WebElement element=driver.findElement(By.id("elementId"));
3. action.moveToElement(element).perform();

49) What kind of keyboard operations can be performed in Selenium?


Selenium lets to perform different kinds of keyboard operations, such as:

 .pressKey("non-text keys") is used for keys like control, function keys etc
that are non-text
 .releaseKey("non-text keys") is used in conjunction with key press event to
simulate releasing a key from keyboard event
 .sendKeys("sequence of characters") is used for passing character sequence
to an input or textbox element.

50) What is JUnit? And what is JUnit Annotation?

JUnit is an open source Java applications testing framework, introduced by Apache. A


process of adding a special form of syntactic metadata to Java source code is called
annotation. JUnit Annotations are: variables, parameters, packages, methods and
classes.

51) What is TestNG and why is it better than JUnit?

TestNG is a testing framework inspired from JUnit and NUnit in a way to use the
merits by both the developers and testers. Here are some new functionalities that
make it more powerful and easier to use, such as:

 test that your code is multithread safe


 support for data-driven testing
 support for parameters
 a variety of tools and plug-ins support (Eclipse, IDEA, Maven, etc...)
 default JDK functions for runtime and logging
 dependent methods for application server testing
 flexible test configuration

52) What kinds of annotations are used in TestNG?

The following kinds of annotations are used in TestNG:

 Test
 BeforeSuite
 AfterSuite
 BeforeTest
 AfterTest
 BeforeClass
 AfterClass
 BeforeMethod
 AfterMethod
53) How to set test case priority in TestNG?

TestNG "Priority" is used to schedule the test cases. In order to achieve, we need to
add an annotation as @Test(priority=??). The default value will be zero for priority. If
you don't mention the priority, it will take all the test cases as "priority=0" and
execute.

The example below shows the usage of the priority for test cases.

As we have not defined the priority for test case "Registration", it will get executed
first and then the other test cases based on priority.

copy

1. import org.testng.annotations.Test;
2. public class testNGPriorityExample {
3. @Test
4. public void registerAccount()
5. {
6. System.out.println("Create an account");
7. }
8. @Test(priority=2)
9. public void sendEmail()
10. {
11. System.out.println("Confirm your email");
12. }
13. @Test(priority=1)
14. public void login ()
15. {
16. System.out.println("Execute login after confirmation");
17. }
18. }

copy

1. import org.testng.annotations.Test;
2. public class testNGPriorityExample {
3. @Test
4. public void registerAccount() {
5. System.out.println("Create an account");
6. }
7. @Test(priority=2)
8. public void sendEmail() {
9. System.out.println("Confirm your account");
10. }
11. @Test(priority=1)
12. public void login() {
13. System.out.println("Execute login after confirmation");
14. }
15. }

54) Explain how you can find broken images in a page using Selenium Web
driver?
You have to follow the next steps to find broken images in a page using Selenium
Web driver:

 get XPath and get the all links on the page using the tag name
 click on every link on the page
 look for 404/500 in the target page title

55) Can captcha and bar code reader be automated by using Selenium?

Neither captcha, no bar code reader can be automated by using Selenium.

56) How to verify tooltip text using Selenium?

The tooltip text in Selenium could be verified by fetching the value of 'title' attribute.
An example:

copy

1. String toolTipText = element.getAttribute("title");

57) How to locate a link using its text in Selenium?

linkText() and partialLinkText() are used for link location.

The examples:

copy

1. WebElement link1 =
driver.findElement(By.linkText(“some_link_test”));
2. WebElement link2 =
driver.findElement(By.partialLinkText(“some_link_part_text”));

58) Can we find all links on a web page?

As all links are of anchor tag 'a', so we can find all of them on a web page by
locating elements of tagName ‘a’:

copy

1. List links = driver.findElements(By.tagName("a"));

59) How can we capture screenshots in Selenium?

We can take the screenshots in selenium by using getScreenshotAs method


of TakesScreenshot interface:

copy
1. File scrFile =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
2. FileUtils.copyFile(scrFile, new File("C:\\screenshot1.jpg"));

60) Explain how colors could be handled in Selenium WebDriver?

To handle colors could be handled in Selenium WebDriver by using Use


getCssValue(arg0) function to get the colors by sending ‘color’ string as an
argument.

61) How many exceptions do you know in Selenium WebDriver?

There are 5 different exceptions Selenium WebDriver:

 NoAlertPresentException,
 NoSuchElementException
 NoSuchWindowException
 TimeoutException
 WebDriverException

62) How will you use Selenium to upload a file?

File uploading action could be performed by using element.sendKeys("path of


file") on the webElement of input tag and type file: < name="fileUpload"
type="file" />

63) What is Robot API?

Robot API is used to control keyboard or mouse to interact with OS windows like
Download pop-up, Alerts, Print Pop-ups, etc. or native Operation System applications
like Notepad, Skype, Calculator, etc.

64) What methods of Robot Class do you know?

Some commonly and popularly used methods of Robot Class during web
automation:

 keyPress(): method with press down arrow key of Keyboard

Example:

copy

1. keyPress(KeyEvent.VK_DOWN)

 keyRelease(): method with release down arrow key of Keyboard:


Example:

copy

1. robot.keyRelease(KeyEvent.VK_DOWN)

 mouseRelease() method will release the right click of your mouse

Example:

copy

1. mouseRelease(InputEvent.BUTTON3_DOWN_MASK)

 mouseMove() method will move mouse pointer to the specified X and Y


coordinates.

Example:

copy

1. robot.mouseMove(point.getX(), point.getY())

 mousePress() method will press the right click of your mouse.

Example :

copy

1. robot.mousePress(InputEvent.BUTTON3_DOWN_MASK)

65) How to execute JavaScript in Selenium?

JavaScriptExecuter is used for JavaScript execution in Selenium.

A simple example:

copy

1. WebDriver driver = new FireFoxDriver();


2. if (driver instanceof JavascriptExecutor) {
3. ((JavascriptExecutor)driver).executeScript("{JavaScript Code}");
4. }

66) Which package can be imported while working with WebDriver?

org.openqa.selenium java -cp bin;jars/* org.testng.TestNG testng.xml

67) How do you get the width of the textbox?


You can get the width of the textbox by using the following command:

copy

1. driver.findElement(By.xpath(“xpath of textbox
”)).getSize().getWidth();
2. driver.findElement(By.xpath(“xpath of textbox
”)).getSize().getHeight()

68) Which web driver implementation is the fastest?

The fastest WebDriver is HtmlUnitDriver. Differing of other drivers (FireFoxDriver,


ChromeDriver etc), it’s non-GUI, while running no browser gets launched.

69) What is the purpose of deSelectAll() method?

It is used to deselect all the options which have been selected from the drop-down
list.

70) How can you switch back from a frame?

defaultContent() method is used to switch back from a frame.

71) How to login into any site if it’s showing any authentication pop-up for
username and password?

You should pass the username and password with URL:

https://username:password@url

https://creds:test@www.test.com

72) What is the purpose of getOptions() method?

getOptions() is used to get the selected option from the drop-down list.

73) What is the difference between getWindowHandles() and


getWindowHandle()?

You can get the browser address using these commands. But if you use
getWindowHandle(), you’ll get the address of the current browser where the control
is and return type is a string. So, if you use getWindowHandles(), you will get the
address of all the open browser and its return type is an iterator.

74) Explain how you can use recovery scenario with Selenium?

You can use recovery scenario in accordance with the programming language.
If it is Java then you can use exception handling to overcome same.

75) How do you send ENTER/TAB keys in WebDriver?

use click() or submit() methods are used for ENTER. But, don’t forget
that submit() method is used only if type=’submit’.

You can use Actions class act.sendKeys(Keys.ENTER) for TAB.

76) How to Handle Alerts in Selenium WebDriver?

Here are a few methods of Alerts handling which are widely used in Selenium
Webdriver.

 void dismiss() is used to click on the 'Cancel' button of the alert.

copy

1. driver.switchTo().alert().dismiss();

 void accept() is used to click on the 'OK' button of the alert.

copy

1. driver.switchTo().alert().accept();

 String getText() is used to capture the alert message.

copy

1. driver.switchTo().alert().getText();

 void sendKeys(String stringToSend) is used to send some data to alert box.

copy

1. driver.switchTo().alert().sendKeys("Text");

77) What is a data-driven framework?

The Data Driven test design framework follows a design paradigm where test logic is
fixed but varies the test data. The data itself can be in different repositories like a
simple .csv file, .json file or .xls sheet, or database and can add the tests merely
updating those external files or DB (instead of placing in test code itself).

78) What is a keyword-driven framework?


The keyword driven framework is a methodology where actions or steps are treated
as keywords. These keywords (like click, move, type etc.,) are stored in some external
repositories along just like data (in .csv/.json/.xls/DB).

79) What is the hybrid framework?

The combination of data driven and keyword driven framework is called the hybrid.
Here the operations/instructions/keywords in a separate repository
(.csv/.xls/.json/DB) and data is in separate (.csv/.xls/.json/db from data provider) and
the tests/driver would read both and perform the actual tests automatically. In this
design, we get the best of both methodologies, and it is kind of practical in most of
the automation cases.

80) What are the main advantages of Selenium Grid?

Selenium Grid has following advantages: multi-browser testing, parallel test case
execution, multi-platform testing.

81) What is a hub in Selenium Grid?

Selenium Grid hub is a central point or a server that controls the test executions on
the different machines.

82) What is a node in Selenium Grid?

Selenium Grid node is a hub attached machine, which has instances running the test
scripts. Unlike a hub, there can be more than one nodes in Selenium Grid.

83) Could you explain the line of code Webdriver driver = new FirefoxDriver();.

‘WebDriver' is an interface and we are creating an object of type WebDriver


instantiating an object of FirefoxDriver class.

84) What is the purpose of creating a reference variable- 'driver' of type


WebDriver instead of directly creating a FireFoxDriver object or any other
driver's reference in the statement Webdriver driver = new FirefoxDriver();?

We can use the same variable to work with multiple browsers like ChromeDriver,
IEDriver by creating a reference variable of type WebDriver.

85) How can you create HTML test report from your test script?

There are three ways of HTML test report creation:

 using inbuilt default.html to get the HTML report in TestNG


 with the ANT help in JUnit
 using XSL jar for converting XML content to HTML in own customized reports

86) What could be the cause of Selenium WebDriver test to fail?

There are some causes of Selenium WebDriver test to fail:

 SeleniumWebDriver element waiting to access did not appear on the web


page and the operation timed out
 SeleniumWebDriver is trying to access not created element
 SeleniumWebDriver cannot locate the element, because the locator has been
changed

87) Explain how can you debug the tests in Selenium IDE?

The tests could be debugged in such way:

 insert a break point from the location from where you want to execute test
step by step
 run the test case
 test case execution will be paused at the given break point
 click on the blue button to continue with the next statement
 to continue executing all the commands at a time click on the “Run” button

88) What is the testng.xml file used for?

testng.xml file is used to configure the whole a test suite. Here we can create a test
suite, create test groups, mark tests for parallel execution, add listeners and pass
parameters to test scripts. It can be used for the further test suite triggering.

89) What is the difference between @Factory and @DataProvider annotation?

@DataProvider is concerned to individual test methods and run the specific


methods for many times. @Factory method creates test class instances and runs all
the test methods in that class with different data. sets.

90) In which format does source view show the script in Selenium IDE?

The script is shown by Selenium IDE source view in XML format.

91) How could AJAX controls be handled in WebDriver?

AJAX allows the Web page to retrieve small amounts of data from the server without
reloading the entire page.
The different wait methods should be applied for testing Ajax application:

 ThreadSleep
 Implicit Wait
 Explicit Wait
 WebdriverWait
 Fluent Wait

92) What is the FirefoxDriver, class or an interface? And which interface does it
implement?

FirefoxDriver is a Java class. It implements all the methods available in the interface.

93) How can we make one test method dependent on other using TestNG?

We can make one test method run only after successful execution of dependent test
method by using dependsOnMethods parameter inside @Test annotation in TestNG:
@Test(dependsOnMethods = { "preTests" })

94) How could you explain the main difference between WebDriver and RC?

Selenium WebDriver drives the browser using built-in support. RC injects JavaScript
function into browsers when the page is loaded.

95) What is IntelliJ?

IntelliJ is an IDE that helps users to write code for Selenium better and faster. It could
be used as an option to Java bean and Eclipse.

96) What are the advantages of Using Git Hub For Selenium?

 Members of multiple people team working on the same project can update its
details and inform other team members simultaneously
 You can build the project from the remote repository regularly by using
Jenkins. This helps you to keep track of failed builds.

97) Can we use Selenium RC for tests driving on two different browsers on one
operating system without Selenium Grid?

We can do it if JAVA testing framework is not used. If we use Java client driver of
Selenium, instead of using Java testing framework, TestNG allows us not to use
Selenium Grid.

98) How can we run test cases in parallel using TestNG?


You should just to add these two key value pairs in the suite to run the tests in
parallel:

copy

1. parallel="{methods/tests/classes}"
2. thread-count="{number of threads you want to run
simultaneously}".

99) How would you test your own element locator?

“Find Button” of Selenium IDE is used to test the locator. Clicking on this button,
you will see on screen if your element locator is right or wrong.

Also, you can use “FirePath” plugin in FireFox

100) When AutoIT is used?

AutoIT is used to handle window GUI and non-HTML popups in the application.

101) What API is required for Database Testing in Selenium WebDriver?

JDBC (Java Database Connectivity) API is required for Database Testing in


Selenium WebDriver.

102) What Java API is required for generating pdf reports?

Java API IText is required for generating pdf reports.

103) Explain why to choose Python over Java in Selenium.

Here are some points that favor Python over Java to use with Selenium:

 Python is simpler and more compact compared to Java


 Java uses traditional braces to start and ends blocks, whilePython uses
indentation
 Java employs static typing, whilePython is dynamically typed
 Java programs tend to run slower compared toPython programs

104) How can you handle network latency using Selenium?

You can use driver.manage().timeouts().pageLoadTimeout(); for network latency

105) How can you run Selenium Server other than the default port 4444?
Selenium server could be run on java-jar selenium-server.jar-port other than its
default port.

106) Explain how you can capture server side log Selenium Server?

To capture server side log in Selenium Server, you can use command: java –jar .jar –
log selenium.log

107) What is a framework and what are the frameworks available in RC?

The framework is a collection of libraries and classes for helping testers to automate
test cases. NUnit, JUnit, TestNG, Bromine, RSpec, unit tests are some of the
frameworks available in RC.

108) Explain how can you insert a start point in Selenium IDE?

Selenium IDE can be set in two ways:

 in Selenium IDE right click on the command and the select “Set / Clear Start
Point”
 press “S” key on the keyboard and select the command in Selenium IDE

109) What are the two modes of views in Selenium IDE?

Selenium IDE can be opened as a pop-up window or in side bar

110) What is Object Repository?

Object repository is an essential entity in any UI automation which allows a tester to


store all object that will be used in the scripts in one or more centralized locations
rather than scattered all over the test scripts.

https://geteasyqa.com/qa/qa-interview-questions/
What are QA interview questions in 2017?
QA interview questions with HR professionals is a crucial step to getting the job.
There are numerous interview techniques being used by recruiters – depending on
the role, the seniority and a host of other factors. We want to share with you useful
experience and show the most important things that you should know to get a job.

Can you tell me about your QA interview experience?

My actuality job position is QA Engineer. As a QA person, I used a variety of


platforms and operating systems including Windows 95, Windows 2000, Windows XP
and UNIX. I have experience with testing applications developed in Java, C++, Visual
Basic and so on. I have also tested Mobile Applications on different IOS and Android
platforms to make sure that the applications also works accordingly in mobile
devices. My best skills:

 Written Test Plans, Test Cases, Checklist.


 Tested Web-based applications as well as client server applications.
 Strong knowledge of Smoke Testing, Functional Testing, Backend Testing, BlackBox
Testing, Integration Testing, Regression Testing and UAT (User Acceptance Testing)
Testing
 Worked in different databases like Oracle and DB2 (wrote SQL queries to retrieve
data from the database).

I also worked with a Business Analysts, Project Managers, Business Managers and QA
Leads. I participated in meetings and provided feedback to the Business Analysts.
Why QA?

I was always interested in Development and I wanted to connect my life with IT world
so I decided to start my career as QA Engineer. Why QA? Because the career in
Software Testing involves stringent processes, scripting knowledge, the knack for
details, business understanding, expert communications, an array of different testing
types like security, mobile apps, performance, cloud, etc.
Why do you like this job?

Firstly, because that is the job where the result of your efforts it is a good product
that you want to enjoy. The work is included processing with program data and with
a variety of development options. Search for bugs and writing user cases that
facilitate the development, and allows you to adopt the product for usage by the
user. Here you need to have full information about both the device and the product
in order to find the most hidden bugs or possible malfunctions during the program
operation.

From you resume, I see that you have been working in one place for a very
short period of time. This raises my questions why. Can you explain why?

Sorry, I want to clarify. These are not different workplaces, it’s a different project.
Because my previous job position was a consultant and I was doing project work.
When one project was over, I needed to choose another project.

What did you do in your last project?

My the most recent project was the development an app on Java. It is the application
for web/desktop. First, I’ve compiled all the test plans, in full accordance with case
specifications. Then, various types of testing needed for that task – smoke tests,
functional tests, backend tests, black-box tests, as well as some optional tests like
integration testing, regression testing, and user acceptance. During some work
meetings that followed, I’ve given my feedback on the app performance to project
managers and analysts. But most of the time for this project I have been conducting
backend testing. This meant writing SQL queries into the database. In Addition, I’ve
corrected certain errors with ClearQuest and conducted repeat testing.

Are you better working in a team or working alone?

I get along with other people very well and I like to work in a team. I’d say that I’m a
team player. To my mind, the tasks may be done more efficiently when you have
several meanings concerning some of them.
How to deal with your team members?

I think that I will be working in a big QA department which consists of people with
different lifestyles, hobbies, tastes and so on. From my experience, the first step of
the establishment of nice relationships with your team is to cope with them during
the coffee break.
Do you have any situations in the past where you have some arguments with your
team members?

From my experience, I don’t have any situations where I had some conflict with my
team members.

What do you like about a Manager? And what don’t you like?

I have been very lucky to have had terrific managers during my career so far. In my
last job, I liked the fact that I may go to my manager if I have an issue or ideas and
be able to feel comfortable with expressing my thoughts. Good skills for a Manager it
is organized and monitor team’s work that can help your team accomplish its
objectives efficiently. I don’t like a Manager who unable to make a decision.

Talk about a conflict or challenge you faced at work, and how you handled it?

In my job, I’m dealing with customers and we have been disagreements that needed
to be resolved, so I briefly explained my position and then suggested a plan to
resolve the issue effectively that enabled us to maintain him as a client. I think
everyone should face challenges you will gain knowledge while you face’s challenge.

What did you learn from your previous companies?

I have learned from my previous companies a lot of new. Each of them had their style
of work and management. The team atmosphere in one company differs from others
a lot.

What is your goal?

My goal is to be hired to this job position and to provide a company with the highly-
qualified specialist and then to develop my skills more and more.
What are your career goals?

I want to develop myself in QA and to become the best in this area, learning and
studying as much as I can.And I would like to become a lead and a mentor to help
others in their development.

What is your weakness?

My weakness is that I am very cautious. If I have to do some work and there is a


deadline I will examine it very carefully and many times before deadline.
As a QA Tester, can you tell me the situation when you felt the proudest of it?

I found bugs that crashed the whole system at the end of the testing phase. I tried
the scenarios where the scenarios were NOT mentioned in the test cases. For
example, we can close the windows by clicking X on the page, with “Close” button
and so on. But there is another way that you can close the window, by pressing
Alt+F4 on the keyboard. Not many testers test this scenario. I have done this in my
last two projects. Both the time, the application crashed which became a big issue. I
felt proud.

What are your strengths?

One of my strength is my good memory. I can remember a lot of information and


keep it in my mind for a long period of time. Another my strength is that I am rather
dedicated to my job.

Why do you leave your last job?

I want to develop myself in QA and to become the best in this area, learning and
studying as much as I can. And I would like to become a lead and a mentor to help
others in their development.

What are you expecting from our company?

I am expecting from your company that I will gain my knowledge and improve my
skills and I will do my best in order to enhance the productivity of your company. I
also want to get acquainted with new people who are interested in the same area as
me.

What is your salary requirement?

Salary isn’t my main consideration when making this decision, but in recent years my
compensation has ranged between _ and _.
What do you want to be in next 2-5 years?

I plan to raise my level to Middle QA Engineer and become a QA lead.” Why QA


Lead? Why not something else? I want to know how to handle different jobs how to
manage QA process and so on.

Why are you looking for another job?

At first, I would like to thank my previous company. Where I have a good chance to
learn lots of things like great technical skills, teamwork, time management and
professionalism. Second thing is that I want to be learned new skills and enhance my
knowledge for the better future both things are not filled the that’s the reason I left
my last job. Right now I am looking new challenge where I growth my skills and
development professional and financial growth.

What do you do on your first day of work?

On the first day of my work, I will be provided with a computer and given the User
Name and Password for the computer by support people. After that, I will acquaint
with some documents and members of my team. The next step will be the
implementation of the first task given by my boss and introduction to the documents
which are connected to the project.

Why should we hire you?

I really fit for this position because I have the great experience in this field. I will be a
good team player because I enjoy the team atmosphere. I like the Software testing
process and when team members work hand-in-hand with each other to reach the
goal in the specified time line. I think your company is the right place to explore my
skill and I want to be a part of your success.
Add to Bookmark Email this Post 19K 0

We are all aware of the growing impact of internet and web applications in today’s
world. Almost every aspect of our life is governed by the internet. So much so that,
most businesses rely heavily on the internet for interacting with their customers.
When there is so much dependency on the web application, then they should be
reliable and behave exactly as expected right? So, how can you ensure
reliability? By testing the web applications. This brings up the next question, how
frequently will you be testing them? Doing it manually is time consuming, tedious,
boring, prone to errors and so on. The solution to manual testing is automation
testing. By now, you can guess why automation testing professionals are so much in
demand, and Selenium being one of the best automation testing tool for web apps,
is used by almost every company and these companies don’t seem to stop hiring for
testing job roles. This is what has prompted me to write this blog on the 35 most
frequently asked Selenium interview questions.
Benefits Of Automation Testing

But you might ask, why only Selenium and not any other tool? That is because
Selenium is open source and it’s easy adoption has earned itself the tag of being the
poster boy of web testing tools. With a whopping 300 percent increase in job
postings over the past three years, testing has presented itself as an entry point into
the IT world for professionals from various domains. So, read the entire list of
Selenium interview questions and answers covered in this blog and prepare yourself
for a job interview of a Selenium tester. Let’s get started!

Top 35 Selenium Interview Questions And Answers

The entire set of Selenium interview questions, is divided into three sections:

A. Basic level
B. Advanced level
C. TestNG framework for Selenium

A. Basic Level – Selenium Interview Questions

1. What are the advantages and disadvantages of Selenium over


other testing tools like QTP and RFT?

The advantages of Selenium over QTP and RFT are:

License: Selenium is open source, whereas HP’s QTP and IBM’s RFT are licensed
software.
Environment Support: Selenium supports Windows OS, Linux OS, Solaris OS X (If
browser & JVM or JavaScript support exists), whereas QTP and RFT work only on
Windows OS.
Programming Language Support: Selenium supports Java, C#, Ruby, Python,
Perl, PHP and JavaScript, whereas RFT supports only Java and C# and QTP supports
only VBScript.
Hardware resource consumption during script execution: Selenium consumes
very less hardware resource, but QTP and RFT a lot of hardware resource.
Coding experience: For Selenium, coding skills should be very good along with
technical capabilities of integrating the framework, whereas coding experience and
skills are not that much needed for QTP and RFT.

2. What are the significant changes in upgrades in various


Selenium versions?

Selenium v1 included only three suite of tools: Selenium IDE, Selenium RC and
Selenium Grid. Note that there was no WebDriver in Selenium v1. Selenium
WebDriver was introduced in Selenium v2. With the onset of WebDriver, Selenium
RC got deprecated and is not in use since. Older versions of RC is available in the
market though, but support for RC is not available. Currently, Selenium v3 is in use,
and it comprises of IDE, WebDriver and Grid.

IDE is used for recording and playback of tests, WebDriver is used for testing
dynamic web applications via a programming interface and Grid is used for
deploying tests in remote host machines.

3. Explain the different exceptions in Selenium WebDriver.

Exceptions in Selenium are similar to exceptions in other programming languages.


The most common exceptions in Selenium are:
TimeoutException: This exception is thrown when a command performing an
operation does not complete in the stipulated time.
NoSuchElementException: This exception is thrown when an element with given
attributes is not found on the web page.
ElementNotVisibleException: This exception is thrown when the element is
present in DOM (Document Object Model), but not visible on the web page.
StaleElementException: This exception is thrown when the element is either
deleted or no longer attached to the DOM.

4. What is exception test in Selenium?

An exception test is an exception that you expect will be thrown inside a test class.
If you have written a test case in such way that it should throw an exception, then
you can use the @Test annotation and specify which exception you will be expecting
by mentioning it in the parameters. Take a look at the example
below:@Test(expectedException = NoSuchElementException.class)

Do note the syntax, where the exception is suffixed with .class

5. Why and how will you use an Excel Sheet in your project?

The reason we use Excel sheets is because it can be used as data source for tests.
An excel sheet can also be used to store the data set while performing DataDriven
Testing. These are the two main reasons for using Excel sheets.

When you use the excel sheet as data source, you can store the following:

 Application URL for all environments: You can specify the URL of the
environment in which you want to do the testing like: development
environment or testing environment or QA environment or staging
environment or production/ pre-production environment.
 User name and password credentials of different environments: You
can store the access credentials of the different applications/ environments in
the excel sheet. You can store them in encoded format and whenever you
want to use them, you can decode them instead of leaving it plain and
unprotected.

 Test cases to be executed: You can list down the entire set of test cases in
a column and in the next column, you can specify either Yes or No which
indicates if you want that particular test case to be executed or ignored.

When you use the excel sheet for DataDriven Test, you can store the data for
different iterations to be performed in the tests. For example while testing a web
page, the different sets of input data that needs to be passed to the test box can be
stored in the excel sheet.

6. How can you redirect browsing from a browser through some


proxy?

Selenium provides a PROXY class to redirect browsing from a proxy. Look at the
example below:
1
String PROXY = “199.201.125.147:8080”;
2

3 org.openqa.selenium.Proxy proxy = new.org.openqa.selenium.Proxy();

4 proxy.setHTTPProxy(Proxy)

5 .setFtpProxy(Proxy)

6 .setSslProxy(Proxy)

7 DesiredCapabilities cap = new DesiredCapabilities();

cap.setCapability(CapabilityType.PROXY, proxy);
8
WebDriver driver = new FirefoxDriver(cap);
9

7. What is POM (Page Object Model)? What are its advantages?

Page Object Model is a design pattern for creating an Object Repository for web UI
elements. Each web page in the application is required to have it’s own
corresponding page class. The page class is thus responsible for finding the
WebElements in that page and then perform operations on those WebElements.

The advantages of using POM are:


 Allows us to separate operations and flows in the UI from Verification –
improves code readability
 Since the Object Repository is independent of Test Cases, multiple tests can
use the same Object Repository
 Reusability of code

8. What is Page Factory?

Page Factory gives an optimized way to implement Page Object Model. When we say
it is optimized, it refers to the fact that the memory utilization is very good and also
the implementation is done in an object oriented manner.

Page Factory is used to initialize the elements of the Page Object or instantiate the
Page Objects itself. Annotations for elements can also be created (and
recommended) as the describing properties may not always be descriptive enough
to differentiate one object from the other.

The concept of separating the Page Object Repository and Test Methods is followed
here also. Instead of having to use ‘FindElements’, we use annotations
like: @FindBy to find WebElement, and initElements method to initialize web
elements from the Page Factory class.

@FindBy can
accept tagName, partialLinkText, name, linkText, id, css, className & xpath
as attributes.

9. What are the different types of WAIT statements in Selenium


WebDriver? Or the question can be framed like this: How do you
achieve synchronization in WebDriver?

There are basically two types of wait statements: Implicit Wait and Explicit Wait.

Implicit wait instructs the WebDriver to wait for some time by polling the DOM. Once
you have declared implicit wait, it will be available for the entire life of the
WebDriver instance. By default, the value will be 0. If you set a longer default, then
the behavior will poll the DOM on a periodic basis depending on the browser/ driver
implementation.

Explicit wait instructs the execution to wait for some time until some condition is
achieved. Some of those conditions to be attained are:

 elementToBeClickable
 elementToBeSelected
 presenceOfElementLocated
10. Write a code to wait for a particular element to be visible on a
page. Write a code to wait for an alert to appear.

We can write a code such that we specify the XPath of the web element that needs
to be visible on the page and then ask the WebDriver to wait for a specified time.
Look at the sample piece of code below:
1 WebDriverWait wait=new WebDriverWait(driver, 20);

2 Element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( “<xpath

Similarly, we can write another piece of code asking the WebDriver to wait until an
error appears like this:
1 WebDriverWait wait=new WebDriverWait(driver, 20);

2 Element = wait.until(ExpectedConditions.alertIsPresent());

11. What is the use of JavaScriptExecutor?

JavaScriptExecutor is an interface which provides a mechanism to execute


Javascript through the Selenium WebDriver. It provides “executescript” and
“executeAsyncScript” methods, to run JavaScript in the context of the currently
selected frame or window. An example of that is:
1 JavascriptExecutor js = (JavascriptExecutor) driver;

2 js.executeScript(Script,Arguments);

12. How to scroll down a page using JavaScript in Selenium?

We can scroll down a page by using window.scrollBy() function. Example:


1 ((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)");

13. How to scroll down to a particular element?

To scroll down to a particular element on a web page, we can use the


function scrollIntoView(). Example:
1 ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", elemen
14. How to handle keyboard and mouse actions using Selenium?

We can handle special keyboard and mouse events by using Advanced User
Interactions API. The Advanced User Interactions API contains the Actions and the
Action Classes that are needed for executing these events. Most commonly used
keyboard and mouse events provided by the Actions class are in the table below:
Method Description

clickAndHold() Clicks (without releasing) the current mouse location.

dragAndDrop() Performs click-and-hold at the location of the source element, moves.

source, target() Moves to the location of the target element, then releases the mouse.

15. What are different types of frameworks?

The different types of frameworks are:

 Data Driven Framework:-


When the entire test data is generated from some external files like Excel,
CSV, XML or some database table, then it is called Data Driven framework.

 Keyword Driven Framework:-


When only the instructions and operations are written in a different file like
an Excel worksheet, it is called Keyword Driven framework.
 Hybrid Framework:-
A combination of both the Data Driven framework and the Keyword Driven
framework is called Hybrid framework.

16. Which files can be used as data source for different


frameworks?

Some of the file types of the dataset can be: excel, xml, text, csv, etc.

17. How can you fetch an attribute from an element? How to


retrieve typed text from a textbox?

We can fetch the attribute of an element by using the getAttribute() method.


Sample code:
1 WebElement eLogin = driver.findElement(By.name(“Login”);

2 String LoginClassName = eLogin.getAttribute("classname");

Here, I am finding the web page’s login button named ‘Login’. Once that element is
found, getAttribute() can be used to retrieve any attribute value of that element and
it can be stored it in string format. In my example, I have retrieved ‘classname’
attribute and stored it in LoginClassName.

Similarly, to retrieve some text from any textbox, we can use getText() method. In
the below piece of code I have retrieved the text typed in the ‘Login’ element.
1 WebElement eLogin = driver.findElement(By.name(“Login”);

2 String LoginText = Login.getText ();

In the below Selenium WebDriver tutorial, there is a detailed demonstration of


locating elements on the web page using different element locator techniques and
the basic methods/ functions that can be applied on those elements.
Selenium WebDriver Tutorial For Beginners | Edureka

B. Advanced Level – Selenium Interview Question

18. How to send ALT/SHIFT/CONTROL key in Selenium


WebDriver?

When we generally use ALT/SHIFT/CONTROL keys, we hold onto those keys and
click other buttons to achieve the special functionality. So it is not enough just to
specify keys.ALT or keys.SHIFT or keys.CONTROLfunctions.

For the purpose of holding onto these keys while subsequent keys are pressed, we
need to define two more
methods: keyDown(modifier_key) and keyUp(modifier_key)


Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)


Purpose: Performs a modifier key press and does not release the modifier key.
Subsequent interactions may assume it’s kept pressed.

Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)


Purpose: Performs a key release.
Hence with a combination of these two methods, we can capture the special function
of a particular key.
1 public static void main(String[] args)

2 {

3 String baseUrl = “https://www.facebook.com”;


4 WebDriver driver = new FirefoxDriver();

6 driver.get("baseUrl");

WebElement txtUserName = driver.findElement(By.id(“Email”);


7

8
Actions builder = new Actions(driver);
9
Action seriesOfActions = builder
10
.moveToElement(txtUerName)
11
.click()
12
.keyDown(txtUserName, Keys.SHIFT)
13 .sendKeys(txtUserName, “hello”)

14 .keyUp(txtUserName, Keys.SHIFT)

15 .doubleClick(txtUserName);

16 .contextClick();

.build();
17
seriesOfActions.perform();
18
}
19

20

19. How to take screenshots in Selenium WebDriver?

You can take a screenshot by using the TakeScreenshot function. By


using getScreenshotAs() method you can save that screenshot. Example:
1 File scrFile = ((TakeScreenshot)driver).getScreenshotAs(outputType.FILE);

20. How to set the size of browser window using Selenium?

To maximize the size of browser window, you can use the following piece of code:
driver.manage().window().maximize(); – To maximize the window

To resize the current window to a particular dimension, you can use


the setSize() method. Check out the below piece of code:
1 System.out.println(driver.manage().window().getSize());

2 Dimension d = new Dimension(420,600);

3 driver.manage().window().setSize(d);

To set the window to a particular size, use window.resizeTo() method. Check the
below piece of code:
1 ((JavascriptExecutor)driver).executeScript("window.resizeTo(1024, 768);");

To witness a demonstration on setting custom sizes for the browser window and
finding various elements on the web page, see the video below.
Selenium Tutorial For Beginners | Edureka

21. How to handle a dropdown in Selenium WebDriver? How to


select a value from dropdown?

Questions on dropdown and selecting a value from that dropdown are very common
Selenium interview questions because of the technicality involved in writing the
code.

The most important detail you should know is that to work with a dropdown in
Selenium, we must always make use of this html tag: ‘select’. Without using
‘select’, we cannot handle dropdowns. Look at the snippet below in which I have
written a code for a creating a dropdown with three options.
1 <select id="mySelect">

2 <option value="option1">Cars</option>

3 <option value="option2">Bikes</option>

4 <option value="option3">Trains</option>

</select>
5

In this code we use ‘select’ tag to define a dropdown element and the id of the
dropdown element is ‘myselect’. We have 3 options in the dropdown: Cars, Bikes
and Trains. Each of these options, have a ‘value’ attribute also assigned to them.
First option from dropdown has value assigned as ‘option1’, second option has value
= ‘option2’ and similarly third option has value assigned as ‘option3’.

If you are clear with the concept so far, then you can proceed to the next aspect of
choosing a value from the dropdown. This is a 2 step process:
1. Identify the ‘select’ html element (Because dropdowns must have the ‘select’
tag)
2. Select an option from that dropdown element

To identify the ‘select’ html element from the web page, we need to use
findElement() method. Look at the below piece of code:
1 WebElement mySelectElement = driver.findElement(By.id("mySelect"));

2 Select dropdown = new Select(mySelectElement);

Now to select an option from that dropdown, we can do it in either of the three
ways:

1. dropdown.selectByVisibleText(“Bikes”); → Selecting an option by the text that


is visible
2. dropdown.selectByIndex(“1”); → Selecting, by choosing the Index number of
that option
3. dropdown.selectByValue(“option2”); → Selecting, by choosing the value of
that option

Note that from the above example, in all the three cases, “Bikes” will be chosen
from the dropdown. In the first case, we are choosing by visible text on the web
page. When it comes to selection by index, 1 represents “Bikes” because indexing
values start from 0 and then get incremented to 1 and 2. Finally in case of selection
by value attribute, ‘option2’ refers to “Bikes”. So, these are the different ways to
choose a value from a dropdown.

22. How to switch to a new window (new tab) which opens up


after you click on a link?

If you click on a link in a web page, then for changing the WebDriver’s focus/
reference to the new window we need to use the switchTo() command. Look at the
below example to switch to a new window:
driver.switchTo().window();

Here, ‘windowName’ is the name of the window you want to switch your reference
to.

In case you do not know the name of the window, then you can use
the driver.getWindowHandle()command to get the name of all the windows that
were initiated by the WebDriver. Note that it will not return the window names of
browser windows which are not initiated by your WebDriver.
Once you have the name of the window, then you can use an enhanced for loop to
switch to that window. Look at the piece of code below.
1 String handle= driver.getWindowHandle();

2 for (String handle : driver.getWindowHandles())

3 {

4 driver.switchTo().window(handle);

}
5

23. How do you upload a file using Selenium WebDriver?

To upload a file we can simply use the command element.send_keys(file


path). But there is a prerequisite before we upload the file. We have to use the html
tag: ‘input’ and attribute type should be ‘file’. Take a look at the below example
where we are identifying the web element first and then uploading the file.
1 <input type="file" name="uploaded_file" size="50" class="pole_plik">

2 element = driver.find_element_by_id(”uploaded_file")

3 element.send_keys("C:\myfile.txt")

24. Can we enter text without using sendKeys()?

Yes. We can enter/ send text without using sendKeys() method. We can do it using
JavaScriptExecutor.

How do we do it?
Using DOM method of, identification of an element, we can go to that particular
document and then get the element by its ID (here login) and then send the text by
value. Look at the sample code below:
1 JavascriptExecutor jse = (JavascriptExecutor) driver;

2 jse.executeScript("document.getElementById(‘Login').value=Test text without sendkeys

25. Explain how you will login into any site if it is showing any
authentication popup for username and password?

Since there will be popup for logging in, we need to use the explicit command and
verify if the alert is actually present. Only if the alert is present, we need to pass the
username and password credentials. The sample code for using the explicit wait
command and verifying the alert is below:
1 WebDriverWait wait = new WebDriverWait(driver, 10);

2 Alert alert = wait.until(ExpectedConditions.alertIsPresent());

3 alert.authenticateUsing(new UserAndPassword(**username**, **password**));

26. Explain how can you find broken links in a page using
Selenium WebDriver?

This is a trick question which the interviewer will present to you. He can provide a
situation where in there are 20 links in a web page, and we have to verify which of
those 20 links are working and how many are not working (broken).

Since you need to verify the working of every link, the workaround is that, you need
to send http requests to all of the links on the web page and analyze the response.
Whenever you use driver.get() method to navigate to a URL, it will respond with a
status of 200 – OK. 200 – OK denotes that the link is working and it has been
obtained. If any other status is obtained, then it is an indication that the link is
broken.

But how will you do that?


First, we have to use the anchor tags <a> to determine the different hyperlinks on
the web page. For each <a> tag, we can use the attribute ‘href’ value to obtain the
hyperlinks and then analyze the response received for each hyperlink when used
in driver.get() method.

27. Which technique should you consider using throughout the


script “if there is neither frame id nor frame name”?

If neither frame name nor frame id is available, then we can use frame by index.

Let’s say, that there are 3 frames in a web page and if none of them have frame
name and frame id, then we can still select those frames by using frame (zero-
based) index attribute. Each frame will have an index number. The first frame would
be at index “0”, the second at index “1” and the third at index “2”. Once the frame
has been selected, all subsequent calls on the WebDriver interface will be made to
that frame.
1 driver.switchTo().frame(int arg0);

C. TestNG Framework For Selenium – Selenium Interview


Questions

28. What is the significance of testng.xml?

I’m pretty sure you all know the importance of TestNG. Since Selenium does not
support report generation and test case management, we use TestNG framework
with Selenium. TestNG is much more advanced than JUnit, and it makes
implementing annotations easy. That is the reason TestNG framewrok is used with
Selenium WebDriver.

But have you wondered where to define the test suites and grouping of test classes
in TestNG?

It is by taking instructions from the testng.xml file. We cannot define a test suite in
testing source code, instead it is represented in an XML file, because suite is the
feature of execution. The test suite, that I am talking about is basically a collection
of test cases.

So for executing the test cases in a suite, i.e a group of test cases, you have to
create a testng.xml file which contains the name of all the classes and methods that
you want to execute as a part of that execution flow.

Other advantages of using testng.xml file are:

 It allows execution of multiple test cases from multiple classes


 It allows parallel execution
 It allows execution of test cases in groups, where a single test can belong to
multiple groups

29. What is parameterization in TestNG? How to pass parameters


using testng.xml?

Parameterization is the technique of defining values in testng.xml file and sending


them as parameters to the test class. This technique is especially useful when we
need to pass multiple login credentials of various test environments. Take a look at
the code below, in which “myName” is annotated as a parameter.
public class ParameterizedTest1{
1
@Test
2
@Parameters("myName")
3 public void parameterTest(String myName) {

4 System.out.println("Parameterized value is : " + myName);

}
5
}
6

To pass parameters using testng.xml file, we need to use ‘parameters’ tag. Look at
the below code for example:
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
3 <suite name=”CustomSuite">

4 <test name=”CustomTest”>

5 <parameter name="myName" value=”John"/>

6 <classes>

7 <class name="ParameterizedTest1" />

</classes>
8
</test>
9
</suite>
10

To extensively understand the working of TestNG and it’s benefit when used with
Selenium, watch the below Selenium tutorial video.
Selenium Training | TestNG Framework For Selenium | Edureka

30. Explain DataProviders in TestNG using an example. Can I call a


single data provider method for multiple functions and classes?

DataProvider is a TestNG feature, which enables us to write DataDriven tests. When


we say, it supports DataDriven testing, then it becomes obvious that the same test
method can run multiple times with different data-sets. DataProvider is in fact
another way of passing parameters to the test method.

@DataProvider marks a method as supplying data for a test method. The


annotated method must return an Object[] where each Object[] can be assigned to
parameter list of the test method.
To use the DataProvider feature in your tests, you have to declare a method
annotated by @DataProvider and then use the said method in the test method
using the ‘dataProvider‘ attribute in the Test annotation.

As far as the second part of the question is concerned, Yes, the same DataProvider
can be used in multiple functions and classes by declaring DataProvider in separate
class and then reusing it in multiple classes.

31. How to skip a method or a code block in TestNG?

If you want to skip a particular test method, then you can set the ‘enabled’
parameter in test annotation to false.
@Test(enabled = false)

By default, the value of ‘enabled’ parameter will be true. Hence it is not necessary to
define the annotation as true while defining it.

32. What is soft assertion in Selenium? How can you mark a test
case as failed by using soft assertion?

Soft Assertions are customized error handlers provided by TestNG. Soft Assertions
do not throw exceptions when assertion fails, and they simply continue to the next
test step. They are commonly used when we want to perform multiple assertions.

To mark a test as failed with soft assertions, call assertAll() method at the end of
the test.

33. Explain what is Group Test in TestNG?

In TestNG, methods can be categorized into groups. When a particular group is


being executed, all the methods in that group will be executed. We can execute a
group by parameterizing it’s name in group attribute of@Test annotation.
Example: @Test(groups={“xxx”})
@Test(groups={“Car”})
1
public void drive(){
2
system.out.println(“Driving the vehicle”);
3
}
4

5
@Test(groups={“Car”})
6 public void changeGear() {

7 system.out.println("Change Gears”);

}
8

9
@Test(groups={“Car”})
10
public void accelerate(){
11
system.out.println(“Accelerating”);
12
}
13

14

34. How does TestNG allow you to state dependencies? Explain it


with an example.

Dependency is a feature in TestNG that allows a test method to depend on a single


or a group of test methods. Method dependency only works if the “depend-on-
method” is part of the same class or any of the inherited base classes (i.e. while
extending a class). Syntax:
@Test(dependsOnMethods = { “initEnvironmentTest” })
1 @Test(groups={“Car”})

2 public void drive(){

system.out.println(“Driving the vehicle”);


3
}
4

5
@Test(dependsOnMethods={“drive”},groups={cars})
6
public void changeGear() {
7
system.out.println("Change Gears”);
8
}
9

10 @Test(dependsOnMethods={“changeGear”},groups={“Car”})

11 public void accelerate(){

12 system.out.println(“Accelerating”);
13 }

14

35. Explain what does @Test(invocationCount=?) and


@Test(threadPoolSize=?) indicate.

@Test(invocationCount=?) is a parameter that indicates the number of times this


method should be invoked.
@Test(threadPoolSize=?) is used for executing suites in parallel. Each suite can
be run in a separate thread.

To specify how many times @Test method should be invoked from different threads,
you can use the attributethreadPoolSize along with invocationCount. Example:
1 @Test(threadPoolSize = 3, invocationCount = 10)

2 public void testServer() {

3 }

So this brings us to the end of the Selenium interview questions blog. Alternatively,
you can check out this video on Selenium interview questions delivered by an
industry expert where he also talks about the industry scenario and how questions
will be twisted and asked in an interview.
Selenium Interview Questions And Answers | Edureka

If you wish to learn Selenium and build a career in the testing domain, then check
out our interactive, live-online Selenium 3.0 Certification Training here, that comes
with 24*7 support to guide you throughout your learning period.

Got a question for us? Please mention it in the comments section and we will get
back to you.

Anda mungkin juga menyukai