1 : What Is Selenium WebDriver/Selenium ?
Answer :

What Is Selenium WebDriver?

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.

2 : Tell Me WebDriver Supported Browsers?

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.
Selenium WebDriver Supported Browsers

Firefox Driver – For Mozilla Firefox browser

Internet Explorer Driver – For Internet Explorer browser

Chrome Driver – For Google Chrome browser

HtmlUnit Driver – GUI-Less(Headless) browser for Java programs

Opera Driver – For Opera browser

3 : Tell Me WebDriver Supported Mobile Application Testing Drivers?

Answer : We can get support of mobile software application testing using Selenium webdriver. Selenium WebDriver supports bellow given drivers to test mobile application.

selenium supported mobile app testing drivers

AndroidDriver

OperaMobileDriver

IPhoneDriver

4 : Which Programming Languages Supported By Selenium WebDriver To Write Test Cases?

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.

Selenium supported languages

Java

C#

Python

Ruby

Perl

PHP

5 : Which Different Element Locators Supported By Selenium WebDriver?
Answer : Selenium WebDriver supports bellow given element locators.

Selenium supported element locators

XPath Locator

CSSSelector Locator 

ClassName Locator 

ID Locator 

Name Locator 

LinkText Locator 

PartialLinkText Locator 

TagName Locator 


Points to remember for selenium interview

Few points to remember about selenium when you are going for selenium interview. As interviewer may wants to check your knowledge on these things too.

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.

7. What are the benefits of test automation? : 

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.

8. Why selenium as automation tool?

It is Open-source testing tool.

Able to operate it on almost all OS.

Selenium support multiple languages to create test scripts so you can choose your preferred language.

Selenium support multiple browsers.

Good online support.

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.

We can use selenium to test web applications in mobile too.

It is not only testing tool but if you have repetitive web-based tasks then you can use selenium to perform those tasks automatically.

WebDriver Automation Testing Interview Questions And Answers- Part 2

6 : What are the benefits of automation testing.

Answer : We can get bellow given benefits If automate our software testing process.

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.

7 : Does Selenium WebDriver Support Record And Playback Facility?

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.

https://1.bp.blogspot.com/-bHsKhoWAbx4/VALbMTqz_aI/AAAAAAAABJs/jcyjfAUaJTw/s1600/Export%2Btest%2Bcase%2BIn%2Bwebdriver%2Bformate.PNG


8 : Which Operating systems support Selenium WebDriver?
Answer : At present, Mainly bellow given operating systems support Selenium WebDriver.

Windows – Windows XP, Windows 7, Windows 8 and Windows 8.1

Apple OS X

Linux – Ubuntu. Other versions of linux should support too.

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.

It has multi-browser support.

Multi-OS support.

Multi types of locators support. So If one not works, We can use another type.

Web as well mobile application testing support.

Many testers are using selenium WebDriver to automate their testing process. So getting solution of any complex Issue very easily on Internet.

It Is extendable and flexible.

Continues support from WebDriver’s development team to Improve the API and resolve current Issues.

10 : Which OpenSource Framework Is Supported In WebDriver With Java?
Answer : Bellow given 2 java frameworks are supported by selenium WebDriver.
JUnit

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.

WebDriver driver = new FirefoxDriver();


12 : What Is XPath and what Is use of It In WebDriver?

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.

14 : What is the difference between absolute XPath and relative XPath?

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’]


15 : How To Handle Dynamic Changing IDs In XPath. 
Example : //div[@id=’post-body-3647323225296998740′]/div[1]/form[1]/input[1]
In this XPath “3647323225296998740” Is changing every time when reloading the page. How to handle this situation?


Answer : There are many different alternatives In such case.

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

16 : How to press ENTER key button on text box In selenium webdriver?

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);


17 : How many types of waits available In selenium WebDriver

Answer : There are two types of waits available In selenium WebDriver software automation testing tool.

Implicit Wait

Explicit Wait

18 : What Is Implicit Wait In Selenium WebDriver?

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.

19 : What Is Explicit Wait In Selenium WebDriver?

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.

Explicit Wait Example :

WebDriverWait wait = new WebDriverWait(driver, 20);

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);

Selenium WebDriver Job Interview Questions Part – 5

21 : How does selenium RC software testing tool drive the browser? 

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.

22 : How does the selenium WebDriver drive the browser?

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.

23 : Do you need Selenium Server to run your tests In selenium WebDriver?

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”);

Now It will work.

25 : Tell me a reason behind bellow given WebDriver exception and how will you resolve It?

“Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate element”

Answer : You will get this exception when WebDriver Is not able to locate element on the page of software web application using whatever locator you have used In your test. To resolved this Issue, I will check bellow given things.

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. 

 WebDriverWait wait = new WebDriverWait(driver, 25);

wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(“#submitButton”)))

Latest Selenium Interview Questions With Answers Part 6

26 : Can we automate desktop software application’s testing using selenium WebDriver?

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()

28 : Can you tell me a difference between driver.get() and driver.navigate() methods?

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.

It will wait till the whole page gets loaded.

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.

29 : WebDriver has built In Object Repository. Correct me If I am wrong.

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.

http://4.bp.blogspot.com/-h9GbC1O3SMs/VBO1-IGhglI/AAAAAAAABKM/xj6-oKTLYQU/s1600/Prompt%2Bwebdriver.PNG


To Input value In that text box of prompt dialog, You can use bellow given syntax.

driver.switchTo().alert().sendKeys(“Jhon”);

Selenium Questions Part – 8

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

37 : Arrange bellow given drivers In fastest to slowest sequence?

Firefox Driver, HtmlUnit Driver, Internet Explorer Driver.

Answer : HTMLUnit Driver Is faster than all other drivers because It Is not using any UI to execute test cases of software web application. Internet Explorer driver Is slower than Firefox and HtmlUnit driver. So, Fastest to slowest driver sequence Is as bellow.

HtmlUnit Driver

Firefox Driver

Internet Explorer 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.

39 : How to handle Ajax In selenium WebDriver?

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.

<input id=”fk-top-search-box” class=”search-bar-text fk-font-13 ac_input” type=”text” autofocus=”autofocus” value=”” name=”q” />

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’]

//input[starts-with(@id, ‘fk-top-search-box’) and contains(@class,’fk-font-13′)]

43 : Can you tell me two drawbacks of xPath locators as compared to cssSelector locator?

Answer : Two main disadvantage of xPath locator as compared to cssSelector locator are as bellow.

It Is slower than cssSelector locator.

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

It Is very easy to learn and understand for any new user.

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.

new Actions(driver).dragAndDrop(X, Y).build().perform();


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.

Interview Questions For Selenium WebDriver Part 11

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();


We can click on OK button of alert as bellow.
driver.switchTo().alert().accept();

We can click on Cancel button of alert as bellow.
driver.switchTo().alert().dismiss();


51 : Tell me a scenario which we can not automate In selenium WebDriver.

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

53 : Which Is the latest version of JUnit.

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.

54 : Tell me different JUnit annotations and Its usage.

Answer : JUnit has bellow given different annotations.

@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).

@Ignore : @Ignore annotation Is useful to exclude @Test method from execution.

@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.

Answer : Sample JUnit @Test to pass on expected ArithmeticException Is as bellow.

@Test(expected = ArithmeticException.class) 

public void excOnDivision() { 

    int i = 5/0;

}

56 : Write sample JUnit @Test method that fails when unexpected ArithmeticException thrown.

Answer : Sample JUnit @Test to fail on unexpected ArithmeticException Is as bellow.

@Test 

public void excOnDivision() { 

    int i = 5/0;

}

57 : What are the advantages of TestNG over JUnit.

Answer : Advantages of TestNG over JUnit JUnit are as bellow.

TestNG Annotations are simple and Easy to understand.

Easy to parameterize the software test cases In TestNG.

Easy to run software automation test cases In parallel.

Can generate Interactive XSLT test execution reports using TestNG.

JUnit With Selenium WebDriver Interview Questions And Answers Part 13

58 : Tell me main features of JUnit.

Answer : JUnit features are as bellow.

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.

59 : What are different assertions supported by JUnit?

Answer : List of JUnit assertions as bellow.

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)

@SuiteClasses({ junittest1.class, junittest2.class })

public class junittestsuite {

}

In above example, junittest1.class and junittest2.class are test case class names.

61 : For what purpose, assertTrue and assertFalse assertions are used?

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.

public void sumExample() {

 int val1 = 10;

 int val2 = 20;

 int expTotal = 35;

 int actTotal = 0;

 actTotal = val1 + val2;

 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.

64 : Can you describe major features of TestNG?

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.

67 : What are different annotations supported by TestNG ?

Answer : TestNG supports many different annotations to configure Selenium WebDriver software automation test

TestNG With Selenium WebDriver Interview Questions And Answers Part 15

68 : What Is the usage of testng.xml file?

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.

Can specify a group to Include or exclude.

Can pass parameter to use In test case of software web application.

Can specify group dependencies.

Can configure parallel test execution for software web application.

Can define listeners.

69 : How to pass parameter with testng.xml file to use It In test case?

Answer : We can define parameter In testng.xml file using syntax like bellow.

<parameter name=”browser” value=”FFX” />

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.

<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd” >

<suite name=”Test Exclusion Suite”>

  <test name=”Exclusion Test” >

    <classes>

      <class name=”Your Test Class Name”>

       <methods>

       <exclude name=”Your Test Method Name To Exclude”/>

      </methods>

      </class>     

    </classes>

  </test>

</suite>

You need to provide @Test method name In exclude tag to exclude It from execution.

71 : Tell me syntax to skip @Test method from execution.

Answer : You can use bellow given syntax Inside @Test method to skip It from test execution.

throw new SkipException(“Test Check_Checkbox Is Skipped”);

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>

Answer : Parent to child arrangement for above testng tags Is as bellow.

<suite>

<test>

</classes>

<class>

</methods>

TestNG Interview Questions And Answers For Selenium WebDriver Part 16

73 : How to set priority of @Test method? What Is Its usage?

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.

assertEquals VIEW EXAMPLE

assertNotEquals VIEW EXAMPLE

assertTrue VIEW EXAMPLE

assertFalse VIEW EXAMPLE

assertNull VIEW EXAMPLE

assertNotNull VIEW EXAMPLE

75 : Can you tell me usage of TestNG Soft Assertion In selenium webdriver software testing tool?

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.

String Result = driver.findElement(By.xpath(“//input[@id=’Resultbox’]”)).getAttribute(“value”);


79 : What Is the difference between findelement and findElements ?

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.

Answer : XPath for above scenario will be something like bellow.

//div/following-sibling::input

81 : Tell me looks like CSSSelector path of sibling Input element which Is after Div in the DOM.

Answer : CSSSelecor path will looks like bellow.

css=div + input

82 : What Is Parallelism In TestNG?

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

83 : What are the benefits of parallelism over normal execution?

Answer : Using parallelism facility of TestNG In selenium webdriver,

Your software test execution time will be reduced as multiple tests will be executed simultaneously.

Using parallelism, We can verify multithreaded code In software application.

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

85 : What Is dependency test In TestNG?

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”})

    public void LogOut() {

  System.out.println(“LogOut Test code.”);

    }
Above test method Is depends on Login and checkMail test methods.

87 : What Is the syntax to set test method disabled.

Answer : We can use attribute enabled = false with @Test annotation to set test method disabled. Syntax Is as bellow.

@Test(enabled = false)

    public void LogOut() {

  System.out.println(“LogOut Test code.”);

    }
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”);

driver =new FirefoxDriver();

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 : Method name of Actions class to build up actions chain Is “build()”. 

95 : When we can use Actions class In Selenium WebDriver test case? 

Answer : Few of the examples are bellow where can use actions class to perform operations In software web application.

Drag and drop element

Drag and drop by x,y pixel offset 

Selecting JQuery selectable Items 

Moving JQuery slider 

Re-sizing JQuery re-sizable element 

Selecting date from JQuery date picker 

96 : Can we capture screenshot In Selenium WebDriver software testing tool? How?

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.

Answer : WebDriver’s different 5 exceptions are as bellow.

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.

ElementNotSelectableException – It will be thrown when webdriver Is trying to select unselectable element.

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.

1.Using .SendKeys() method
driver.findElement(By.xpath(“//input[@id=’fname’]”)).sendKeys(“Using sendKeys”);

2. Using JavascriptExecutor
((JavascriptExecutor)driver).executeScript(“document.getElementById(‘fname’).value=’Using JavascriptExecutor'”);

3. Using Java Robot class 
driver.findElement(By.xpath(“//input[@id=’fname’]”)).click();

Robot robot = new Robot();

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);

101 : Tell me different ways to verify element present or not on page. 

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.

102 : Why we need to customize Firefox browser profile In webdriver test?

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?

Answer : You can do It In two different ways.

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.

104 : What is Difference between getAttribute() and getText()?

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. 

105 : What is the difference between WebDriver and Remote WebDriver?

Answer : Simple answer for this questions Is as bellow.

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 

Steps To Download And Install AutoIT V3

Creating AutoIt Script To Upload File On Web Page

Upload File In Selenium WebDriver Using AutoIt

110 : I wants to set size and position of my browser window. Do you know how to do it in selenium webdriver?

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.