Top 25 Selenium Webdriver Interview Questions and answers

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

Newer Post Older Post

Leave a Reply