Webdriver (Selenium ) Interview Questions and answers

Question 1: What is Selenium 2.0
Answer: Webdriver is open source automation tool for web application. WebDriver is designed to provide a simpler, more concise programming interface in addition to addressing some limitations in the Selenium-RC API.

Question 2: What is cost of webdriver, is this commercial or open source.
Answer: selenium  is open source and free of cost.

Question 3: how you specify browser configurations with Selenium 2.0?
Answer:  Following driver classes are used for browser configuration
  • AndroidDriver,
  • ChromeDriver,
  • EventFiringWebDriver,
  • FirefoxDriver,
  • HtmlUnitDriver,
  • InternetExplorerDriver,
  • IPhoneDriver,
  • IPhoneSimulatorDriver,
  • RemoteWebDriver
Question 4: How is Selenium 2.0 configuration different than Selenium 1.0?
Answer: In case of Selenium 1.0 you need Selenium jar file pertaining to one library for example in case of java you need java client driver and also Selenium server jar file. While with Selenium 2.0 you need language binding (i.e. java, C# etc) and Selenium server jar if you are using Remote Control or Remote WebDriver.

Question5: Can you show me one code example of setting Selenium 2.0?
Answer: below is example
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/");
driver.findElement(By.cssSelector("#gb_2 > span.gbts")).click();
driver.findElement(By.cssSelector("#gb_1 > span.gbts")).click();
driver.findElement(By.cssSelector("#gb_8 > span.gbts")).click();
driver.findElement(By.cssSelector("#gb_1 > span.gbts")).click();

Question 6: Which web driver implementation is fastest?
Answer: HTMLUnitDriver. Simple reason is HTMLUnitDriver does not execute tests on browser but plain http request – response which is far quick than launching a browser and executing tests. But then you may like to execute tests on a real browser than something running behind the scenes

Question 7: What all different element locators are available with Selenium 2.0?
Answer: Selenium 2.0 uses same set of locators which are used by Selenium 1.0 – id, name, css, XPath but how Selenium 2.0 accesses them is different. In case of Selenium 1.0 you don’t have to specify a different method for each locator while in case of Selenium 2.0 there is a different method available to use a different element locator. Selenium 2.0 uses following method to access elements with id, name, css and XPath locator –
driver.findElement(By.id("HTMLid"));
driver.findElement(By.name("HTMLname"));
driver.findElement(By.cssSelector("cssLocator"));
driver.findElement(By. className ("CalssName”));
driver.findElement(By. linkText ("LinkeText”));
driver.findElement(By. partialLinkText ("PartialLink”));
driver.findElement(By. tagName ("TanName”));
driver.findElement(By.xpath("XPathLocator));

Question 8:  How do I submit a form using Selenium?
Answer:
WebElement el  =  driver.findElement(By.id("ElementID"));
el.submit();

Question 9: How to capture screen shot in Webdriver?
Answer:
File file= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("c:\\name.png"));

Question 10: How do I clear content of a text box in Selenium 2.0?
Answer:  
WebElement el  =  driver.findElement(By.id("ElementID"));
el.clear();

Question 11:  How to execute java scripts function.
Answer:
JavascriptExecutor js = (JavascriptExecutor) driver;
String title = (String) js.executeScript("pass your java scripts");

Question 12:  How to select a drop down value using Selenium2.0?
Answer: See point 16 in below post: 

Question 13: How to automate radio button in Selenium 2.0?
Answer:
WebElement el = driver.findElement(By.id("Radio button id"));

//to perform check operation
el.click()

//verfiy to radio button is check it return true if selected else false
el.isSelected()

Question 14: How to capture element image using Selenium 2.0?

Question 15: How to count total number of rows of a table using Selenium 2.0?
Answer: 
List {WebElement} rows = driver.findElements(By.className("//table[@id='tableID']/tr"));
int totalRow = rows.size();

Question 16:  How to capture page title using Selenium 2.0?
Answer:
String title =  driver.getTitle()

Question 17:  How to store page source using Selenium 2.0?
Answer:
String pagesource = driver.getPageSource()

Question 18: How to store current url using selenium 2.0?
Answer: 
String currentURL  = driver.getCurrentUrl()

Question 19: How to assert text assert text of webpage using selenium 2.0?
Answer:
WebElement el  =  driver.findElement(By.id("ElementID"));
//get test from element and stored in text variable
String text = el.getText();

//assert text from expected
Assert.assertEquals("Element Text", text);

Question 20: How to get element attribute using Selenium 2.0?
Answer:
WebElement el  =  driver.findElement(By.id("ElementID"));
//get test from element and stored in text variable
String attributeValue = el. getAttribute("AttributeName") ;

Question 21: How to double click on element using selenium 2.0?
Answer:
WebElement el  =  driver.findElement(By.id("ElementID"));

Actions builder = new Actions(driver);
builder.doubleClick(el).build().perform();

Question 22: How to perform drag and drop in selenium 2.0?
Answer:
WebElement source  =  driver.findElement(By.id("Source ElementID"));
WebElement destination  =  driver.findElement(By.id("Taget ElementID"));

Actions builder = new Actions(driver);
builder.dragAndDrop(source, destination ).perform();

Question 23: How to maximize window using selenium 2.0?
Answer:
driver.manage().window().maximize();

Question 24: How to verify pdf content using selenium 2.0?
Answer: Go through below post: 

Question25: How to capture video of running scripts in selenium 2.0?
Answer: Go below link:

Question 26: How to verify response 200 code using selenium 2.0?
Answer: Go through below post:

Question 27: How to verify image using selenium 2.0?
Answer: go through below post:

Question 28: How to handle http authentication in selenium 2.0?
Answer: go through below post:

Question 29: Can we automate HTML 5 video using selenium 2.0?
Answer: Go through below post:

Question 30:  What is different between findElement and findElements
Answer : go through below link: 

19 comments:

  1. Tks very much for your post.

    Avoid surprises — interviews need preparation. Some questions come up time and time again — usually about you, your experience and the job itself. We've gathered together the most common questions so you can get your preparation off to a flying start.

    You also find all interview questions at link at the end of this post.

    Source: Ebook Ultimate Guide To Job Interview Answers:

    Best rgs

    ReplyDelete
  2. Great blog very useful information is available. Mainly concentrating on advanced selenium techniques like reading the pdf and validating it, taking screenshots, recording video, validating the HTTP response codes and HTTP status messages.

    ReplyDelete
  3. Seems simply good. May be adding additional latest real time issues will be much helpful.

    ReplyDelete
  4. Simply superb concept and
    all posted content is really helpful

    ReplyDelete
  5. Very Nice post. Thanks for sharing

    ReplyDelete
  6. Very good post. Thank you so much for posting these questions. It helped me to take the interview as well :)

    ReplyDelete

  7. how to catch PHP errors in selenium using java? This is the link for webpage:

    http://selenium.couponapitest.com/page-2.php

    I am new to selenium so please help me on this.

    ReplyDelete
  8. how to catch PHP errors in selenium using java? This is the link for webpage:

    http://selenium.couponapitest.com/page-2.php

    I am new to selenium so please help me on this.

    ReplyDelete
  9. very useful blog thanks a lot for it....
    if you could add a link directing to java question asked with selenium it would be very much helpful.

    ReplyDelete
  10. Thanks for your post,its very useful and it cover's most of it...

    ReplyDelete
  11. It’s really a nice and helpful piece of info. I’m happy that you shared this helpful information with us. Please keep us up to date like this. Thanks for sharing.
    Home automation Hamilton

    ReplyDelete
  12. Hi,

    Can you please tell me how we can execute a url which will open browser, but we have to provide http request headers for that request

    ReplyDelete
  13. Can you plz tell me how we can execute http request with http headers using selennium webdriver?And after executing that request it will open browser page with UI

    ReplyDelete
  14. Thanks for the post, very helpful. For online training on Selenium visit TekSlate.

    ReplyDelete
  15. Welcome Post very usefull informatation.and iam expecting more posts like this please keep updating us........

    ReplyDelete

Leave your comments, queries, suggestion I will try to provide solution