Selenium interview questions - Part 5

41) Tell me a syntax to read JavaScript alert message string, clicking on OK button and clicking on Cancel button.
  • 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();

42) What are the scenarios that we can not automated using Selenium WebDriver?
scenario which we can not automate in selenium WebDriver are as follows
  • Bitmap comparison
  • Automating captcha
  • Bar code
43) What Is the difference between findelement and findElements?
findElement is used to locate and return single element from web page while findElements is used to locate and return multiple elements from web page.

44) What is the method name using which we can builds up the actions chain? 
Method name of Actions class to build up actions chain Is "build()".

45) How to capture screenshot in Selenium WebDriver?
We can use selenium webdriver TakesScreenshot method to capture screenshot.
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(screenShotFile));

46) Tell me any webdriver common exceptions which you faced during test case execution.
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.

47) What are the diffrent ways to type text in text box?
Using .SendKeys() method
driver.findElement(By.xpath("//input[@id='fname']")).sendKeys("Using sendKeys");

Using JavascriptExecutor
((JavascriptExecutor)driver).executeScript("document.getElementById('fname').value='Using JavascriptExecutor'");

48)  What is Difference between getAttribute() and getText()?
getAttribute() method is useful to read WebElement's attribute value like id, name, type etc.
getText() method is useful to read text from element or alert.

49) What are the three different ways to refresh page. Do not use .refresh() method?
driver.get(driver.getCurrentUrl());
driver.navigate().to(driver.getCurrentUrl());
driver.findElement(By.xpath("//h1[@class='title']")).sendKeys(Keys.F5);

50) How to scroll page using JavaScriptExecutor?
// This  will scroll page 400 pixel vertical
JavascriptExecutor jse = ((JavascriptExecutor) driver);
jse.executeScript("scroll(0,400)");



<-- Previous || Next -->

No comments:

Post a Comment