Sunday, July 29, 2018

Selenium Interview Questions which asked in Campanies


1. Which class implements WebDriver interface ?

    RemoteWebDriver
  

2. An element has an id “png_123” but number is changing, how to handle it ?

    starts-with


3. How to get text from hidden element ?

    Element.getAttribute(“textContent”);


4. What is StaleElementReferenceException ?

    It Occurs when Element is entirely deleted from DOM or Page is navigated to    another page.


5. 5 textboxes with same class name but different id, fetch the text present  in all textbox ?

      List <WebElement> li = driver.findElements(By.xpath(“common xpath of text boxes”));

        For (WebElement wb : li)
{

String  textbox_text = wb.getText();

System.out.println(textbox_text);      
}


6. How many ways to click on webelement ?

   Click(), sendKeys(Keys.Enter), sendKeys(ASCII value for left click),     javascriptsExecutor(“arguments[0].click();”, WebElement);


7. How to handle SSL Certification error ?

    DesiredCapabilities capabilities = new Desiredcapabilities();
    capabilities.setCapabilities(CapabilityType.ACCPT_SSL_CERTS,true);


8. How to read property file ?

    Properties pro = new Properties();
    FileInputStream fis =  new FileInputStream(“path of file”);
    Pro.load(fis);


9. How to click on an element without using Click() command ?

    WebElement ele =  driver.findElement(By.xpath(“locatorOfElement”));
    JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript(“arguments[0].click();” , ele);


10. How to enter text in text field without using sendKeys command ?

     WebElement ele =  driver.findElement(By.xpath(“locatorOfTextField”));
     JavascriptExecutor js = (JavascriptExecutor)driver;
     js.executeScript(“arguments[0].value=’Search Selenium’” , ele);


11. How to find broken links on a webpage using selenium ?

     Read below link:

12. List some scenarios which can not be automated using selenium ?

     Capcha, barcode, windows base popup.


13. What is page factory ?

      The PageFactory class in Selenium is an extension to the page object design pattern. It is used to initialize the elements of the page object.


14. How to resize browser window using selenium webdriver ?

      Dimension d = new Dimension(200,800);
      driver.manage().window().setSize(d);


15. How to run the selenium webdriver test from the command line ?

      Need to provide  path till where  testing.xml file resides and then just give the name of          testing.xml file and hit enter.


16. How to perform right click action in Selenium Webdriver ?

      By using Actions class-
    
      WebElement ele =  driver.findElement(By.xpath(“locator”));
      Actions act = new Actions(driver);
      act.ContextClick(ele).build().perform();


17. Explain the line of code WebDriver driver = new FirefoxDriver(); ?

      'WebDriver' is an interface and we are creating an object reference of type WebDriver instantiating an object of Firefox class.


18. What is the purpose of doing this way:
     
        WebDriver driver = new FirefoxDriver();

      If we create a reference variable driver of type WebDriver then we could use the same driver variable to work with any browser of our choice such as IEDriver, SafariDriver etc.


19. What are the different exceptions you have faced in Selenium WebDriver ?

      NoSuchElementException
      NoSuchWindowException
      StaleElementReferenceException
      ElementNotvisibleException
      IllegalStateException


20. What is difference between StaleElementReferenceException and        NoSuchElementException ?

    StaleElementReferenceException :- When Selenium trying to interact with an element at that time page got refreshed or ajax calls happened then selenium throw this exception.
(Internally when selenium interacting the element it creates a random ID by using this selenium interact with the element but if page got refreshed or ajax calls happened then ID is changed, now that ID is stale from the page, So selenium throw this exception.)

   NoSuchElementException :- If element is not present in the DOM or we have given the the wrong locator of the element or element is present in any frame and we haven't switched that frame then selenium throw this exception.
    


21. How to login on any site if it is showing any authentication Pop- up for username and password ?

      To do this we pass the username and password with the url.

      example: http://username:password@url







                               Basics Selenium Interview Questions and Answers


        


No comments:

Post a Comment