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. VIEW EXAMPLE
  • 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. You can VIEW DATADRIVEN FRAMEWORK CREATION TUTORIALS step by step.
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.
  1. TimeoutException - This exception will be thrown when command execution does not complete In given time.
  2. NoSuchElementException - WebDriver software testing tool will throw this exception when element could not be found on page of software web application.
  3. NoAlertPresentException - This exception will be generated when webdriver ties to switch to alert popup but there Is not any alert present on page.
  4. ElementNotSelectableException - It will be thrown when webdriver Is trying to select unselectable element.
  5. ElementNotVisibleException - Thrown when webdriver Is not able to Interact with element which Is available In DOM but It Is hidden.
  6. StaleElementReferenceException - VIEW DESCRIPTION.

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 VIEW EXAMPLE
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. VIEW MORE DETAIL WITH EXAMPLE

2 comments:

  1. Hi,
    I really like your blog, it has the most detailed explanation on almost every topic in selenium.
    Could you please add some information on page object pattern, it would great if you could add page object pattern in your DDF example.
    Thanks

    ReplyDelete
  2. public static boolean isElementPresent(String xPathXpr) {
    return driver.findElement(By.xpath(xPathXpr)) != null;
    }

    ReplyDelete