Part 2 Selenium Webdriver Interview Questions With Answers

1.  What is webdriver?
 WebDriver is a simpler, more concise programming interface in addition to addressing some limitations in  the Selenium-RC API. Selenium-WebDriver was developed to better support dynamic web pages where elements of a page may change without the page itself being reloaded. WebDriver’s goal is to supply a well-designed object-oriented API that provides improved support for modern advanced web-app testing problems.
2.      What are the advantages of selenium2.0/webdriver?
  •         Need no server to start
  •     Easy to code
  •         Has sophisticated API to support wide verity of browsers.
  •     Supports to test dynamic UI web apps.

3.      Difference between the selenium1.0 and selenium 2.0?
Selenium 1.0
Selenium 2.0/Webdriver
1.      It ‘injected’ javascript functions into the browser when the browser was loaded and then used its javascript to drive the AUT within the browser.

2.      Selenium server need to start to run tests
3.      Has some loop-holes in supporting complex UI apps,Javascript security
4.      No support for headless broswers
1.      WebDriver makes direct calls to the browser using each browser’s native support for automation


2.      Not needed unless tests are run on local machine.
3.      Supports even drag and drop features and no security loop-holes
4.      Supports htmlunit driver –headless browser runs fast



4.      What are the Locators are there in selenium 2.0?
It supports locators based on Id,name,xpath,dom,css,class,tagname
5.      How to handle the Ajax Applications in Web driver?
There are 2 types of waits webdriver supports to handle ajax applications to make webdrive sync to execution:
Implicit wait :
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
Explicit wait:   WebDriverWait, FluentWait
WebElement strr = (new WebDriverWait(driver,30)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[starts-with(@id,'yui_3_4_0_1_137509')]/ul/li[2]/a")));
This link explains better about handling ajax in webdriver.

5.      How to handle the multiple windows in web driver?
            driver.switchTo().window(Window ID);

6.      Difference between findelement() and findelements()?
     findELement will find the first matching element.

     findELements will all the matching elements. You'll probably need to loop through all the elements  returned.
7.      How to handle the alerts in web driver?
    driver.switchTo().alert().accept();
 
8.      How to take the screen shots in seelnium2.0?
            File src2 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(src2,new File("d:\\sc2.jpeg"));
9.      What is web driver architecture?
Below link gives better idea of webdriver architecture:
http://www.aosabook.org/en/selenium.html
10.  What is the limitations of web driver?
  • Can not automate desktop applications, supports only web applications
  •  No inbuilt commands to generate good reports
  • Cannot support readily for new browsers




Part 1 Selenium Webdriver Interview Questions With Answers

Here are few questions /answers for selenium interview questions, I will be posting more on selenium RC,GRID,Webdriver in parts.


1.      What are the advantages and disadvantages of Selenium IDE?
Advantages:
1.      It is Opensource
2.      Can generate code in any format like java,python,html,php etc.
3.      Easy to record and play
4.      Can extend the code of IDE using user-extensions
5.      Can increase and decrease the speed of execution
6.      Can run multiple tests at a time
7.      Breakpoint insertion is possible
Disadvantages:
1.      Supports only in Mozilla as add-on,but not for IE,chrome etc
2.      Doesn’t support flow control,data driven testing unless we use third party user-extensions.
3.      Not efficient in running large number of scripts,complex to manage suites.
4.      Detailed results are not available
5.      Supports only web based apps

2.      What is the Difference between id and name?
name as used on the form controls (input, textarea, select, button elements) is radically different from the id attribute on named elements. In this case, the name attribute relates to how data is labeled when sent to server, and multiple elements may share the same name. The id attribute on the other hand is for identifying one unique element for the purposes of scripting, styling, or addressing.
id and name are the two different attributes of web elements.These are used to locate the element on webpage while automating,most of the times id is used, if two elements has same id’s then we can also look for name attribute to locate exact one.
Ex:       //input[@id =”xxx” and @name =”yyy”]
//input[@id=”xxx”]
//input[@name=”yyy”]


3.      What is the difference between Xpath and dom?
DOM: The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTMLXHTML and XML documents. Objects in the DOM tree may be addressed and manipulated by using methods on the objects
Ex: var element=document.getElementById("intro");

XPTAH: XPath, the XML Path Language, is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document.
Ex: //input[@id=”xxx”]

4.      What is the difference between assert and verify command?
Assert : If you use this, the test will be terminated at the point where check fails. The main plus point of this is you can immediately see if the test passed or failed. However, the disadvantage of doing this is the remaining checks and verification that will never be performed and you can not track that.
Verify : This is in contrast, will not terminate the whole test. If you only used Verify commands in your tests, all tests are going to run guaranteed even if any of the checks fails when test is running. However, there is a bit of work in order to find out your results in details

5.      What type of testing we can do by using Senium?
    • Functional automation testing of web applications(Android also)
    • Load testing

webdriver- unable to bind socket 7054 till 45 seconds-solution

Here, I have used below code to solve the exception -unable to bind socket 7054 till 45 seconds,It worked for me.


FirefoxBinary binary = new FirefoxBinary(new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe"));

WebDriver driver = new FirefoxDriver(binary);