Selenium Interview Questions

 

1. What is Selenium?

Ans. Selenium is a robust test automation suite that is used for automating web-based applications. It supports multiple browsers, programming languages, and platforms. know more at Selenium online training

2. What are the different forms of Selenium?

Ans. Selenium comes in four forms-

  1. Selenium WebDriver – Selenium WebDriver is used to automate web applications by directly calling the browser’s native methods.
  2. The Selenium IDE Plugin – Selenium IDE is an open-source test automation tool that works on record and playback principles.
  3. Selenium RC component – Selenium Remote Control(RC) is officially deprecated by Selenium and it used to work using javascript to automate the web applications.
  4. Selenium Grid – Allows Selenium tests to run in parallel across multiple machines.
  5. 3. What are some advantages of Selenium?

    Ans. Following are the advantages of Selenium-

    1. Selenium is open source and free to use without any licensing cost.
    2. It supports multiple languages like Java, Ruby, Python, etc.
    3. Selenium supports multi-browser testing.
    4. It has vast resources and helping community over the internet.
    5. Using Selenium IDE component, non-programmers can also write automation scripts.
    6. Using the Selenium Grid component, distributed testing can be carried out on remote machines.
    7. 4. What are some limitations of Selenium?

      Ans. Following are the limitations of Selenium-

      1. We cannot test desktop applications using Selenium.
      2. We cannot test web services using Selenium.
      3. For creating robust scripts in Selenium Webdriver, programming language knowledge is required.
      4. Also, we have to rely on external libraries and tools for performing tasks like – logging(log4J), testing framework-(TestNG, JUnit), reading from external files(POI for excels), etc.
      5. 5. Which browsers/drivers are supported by Selenium Webdriver?

        Ans. Some commonly used browsers supported by Selenium are-

        1. Google Chrome – ChromeDriver
        2. Firefox – FireFoxDriver
        3. Internet Explorer – InternetExplorerDriver
        4. Safari – SafariDriver
        5. HtmlUnit (Headless browser) – HtmlUnitDriver
        6. Android – Selendroid/Appium
        7. IOS – ios-driver/Appium
        8. 6. What is Selenese? How is it classified?

          Selenese is the set of Selenium commands which are used to test your web application. The tester can test the broken links, the existence of some object on the UI, Ajax functionality, alerts, window, list options, and a lot more using Selenese.

          Action: Commands which interact directly with the application

          Accessors: Allow the user to store certain values to a user-defined variable

          Assertions: Verifies the current state of the application with an expected state

          7. Mention the types of Web locators.

          Locator is a command that tells Selenium IDE which GUI elements ( say Text Box, Buttons, Check Boxes, etc) it needs to operate on. Locators specify the area of action.

          Locator by ID: It takes a string parameter which is a value of the ID attribute which returns the object to findElement() method.

            driver.findElement(By.id(“user”));

          Locator by the link: If your targeted element is a link text then you can use the by.linkText locator to locate that element.

            driver.findElement(By.linkText(“Today’s deals”)).click();

          Locator by Partial link: The target link can be located using a portion of text in a link text element.

            driver.findElement(By.linkText(“Service”)).click();

          Locator by Name: The first element with the name attribute value matching the location will be returned.

            driver.findElement(By.name(“books”).click());

          Locator by TagName: Locates all the elements with the matching tag name

            driver.findElement(By.tagName(“button”).click());

          Locator by classname: This finds elements based on the value of the CLASS attribute. If an element has many classes then this will match against each of them. 

            driver.findElement(By.className(“inputtext”));

          Locator by XPath: It takes a parameter of String which is a XPATHEXPRESSION and it returns an object to findElement() method.

            driver.findElement(By.xpath(“//span[contains(text(),’an account’)]”)).getText();

          Locator by CSS Selector: Locates elements based on the driver’s underlying CSS selector engine.

            driver.findElement(By.cssSelector(“input#email”)).sendKeys(“myemail@email.com”);

          8. What are the types of waits supported by WebDriver?

          webdriver.

          Implicit wait - Implicit wait commands Selenium to wait for a certain amount of time before throwing a “No such element” exception.

          driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);

          Explicit wait - Explicit wait is used to tell the Web Driver to wait for certain conditions before throwing an "ElementNotVisibleException" exception.

          WebDriverWait wait = new WebDriverWait(WebDriver Reference, TimeOut);

          Fluent wait - It is used to tell the web driver to wait for a condition, as well as the frequency with which we want to check the condition before throwing an "ElementNotVisibleException" exception.

          Wait wait = new FluentWait(WebDriver reference).withTimeout(timeout, SECONDS).pollingEvery(timeout, SECONDS).ignoring(Exception.class);

          9. Mention the types of navigation commands 

        9. driver.navigate().refresh(); - This method refreshes the current page

          driver.navigate().forward(); - This method does the same operation as clicking on the Forward Button of any browser. It neither accepts nor returns anything.

          driver.navigate().back(); - This method does the same operation as clicking on the Back Button of any browser. It neither accepts nor returns anything. know more at Selenium training

          10. What is the major difference between driver.close() and driver.quit()?

          driver.close()

          This command closes the browser’s current window. If multiple windows are open, the current window of focus will be closed.

          driver.quit()

           When quit() is called on the driver instance and there are one or more browser windows open, it closes all the open browser windows.

          11. What makes Selenium such a widely used testing tool? Give reasons.

          1. Selenium is easy to use since it’s essentially developed in JavaScript.
          2. Selenium can test web applications against browsers like Firefox, Opera, Chrome, and Safari, to name a few. 
          3. The test code can be written in various programming languages like Java, Perl, Python, and PHP. 
          4. Selenium is platform-independent, and can be deployed on different Operating systems like Windows, Linux, and Macintosh. 
          5. Selenium can be integrated with third-party tools like JUnit and TestNG for test management
          6. 12. How to type text in an input box using Selenium?

            sendKeys() is the method used to type text in input boxes 

            Consider the following example - 

              WebElement email = driver.findElement(By.id(“email”)); - Finds the “email” text using the ID locator

          7. 13. How to click on a hyperlink in Selenium?

            driver.findElement(By.linkText(“Today’s deals”)).click();

            The command finds the element using link text and then clicks on that element, where after the user would be redirected to the corresponding page. know more at Selenium online course

            driver.findElement(By.partialLinkText(“Service”)).click();

            The above command finds the element based on the substring of the link provided in the parenthesis and thus partialLinkText() finds the web element. 

            14. How to scroll down a page using JavaScript?

            scrollBy() method is used to scroll down the webpage

            General syntax:

            executeScript("window.scrollBy(x-pixels,y-pixels)");

            First, create a JavaScript object

               JavascriptExecutor js = (JavascriptExecutor) driver;

            Launch the desired application

               driver.get(“https://www.amazon.com”);

            Scroll down to the desired location

               js.executeScript("window.scrollBy(0,1000)"); 

            The window is not scrolled vertically by 1000 pixels

            15. How to assert the title of a webpage? 

            Get the title of the webpage and store in a variable

                String actualTitle = driver.getTitle();

            Type in the expected title

               String expectedTitle = “abcdefgh";

            Verify if both of them are equal

               if(actualTitle.equalsIgnoreCase(expectedTitle))

               System.out.println("Title Matched");

              else

              System.out.println("Title didn't match");

            Alternatively,

               Assert.assertEquals(actualTitle, expectedTitle

          8. 16. How to mouse hover over a web element? 

            Actions class utility is used to hover over a web element in Selenium WebDriver know more at Selenium online training from India

            Instantiate Actions class.

                Actions action = new Actions(driver);

            In this scenario, we hover over search box of a website

              actions.moveToElement(driver.findElement(By.id("id of the searchbox"))).perform();

          9. 17. How to retrieve CSS properties of an element?

            getCssValue() method is used to retrieve CSS properties of any web element

            General Syntax:

              driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);

            Example:

               driver.findElement(By.id(“email“)).getCssValue(“font-size”);

Comments

Popular posts from this blog

What is Azure?

SharePoint Interview Questions

Selenium Interview Questions