Tuesday, June 28, 2022

Selenium Interview Questions and Answers - PART 1

1. What is Selenium?

  •  Selenium is an automation testing tool that is used for automating web-based applications.
  •  It supports multiple browsers, programming languages, and platforms.

2. What are the different forms of selenium?

  •  Selenium WebDriver - It is used to automate web applications using browser methods.
  •  Selenium IDE - It is a plugin that works on record and playback principles.
  •  Selenium RC - Selenium Remote Control(RC) is officially deprecated by Selenium and it used to work on javascript to automate web applications.
  •  Selenium Grid - Allows selenium tests to run in parallel across multiple machines.

3. Advantages of selenium?

  •  Selenium is open source and free to use without any licensing cost.
  •  It supports multiple languages like java, ruby, python, etc.
  •  It supports multi-browser testing.
  •  Using the selenium ide component, non-programmers can also write automation scripts.

4. Limitations of selenium?

  •  We cannot test the desktop applications using selenium.
  •  We cannot test web services using selenium.

5. Which browsers/drivers are supported by the selenium web driver?

 Google chrome - ChromeDriver

 Firefox - FireFoxDriver

 Internet Explorer - InternetExplorerDriver

 Safari - SafariDriver

6. What are the testing types supported by the selenium web driver?

  •  Selenium web driver can be used for performing automated functional and regression testing.

7.Different locators in selenium?

 id,xpath,cssSelector,className,tagName,name,linkText,partialLinkText

8.What is an XPath?

  •  Xpath or XML path is a query language for selecting nodes from XML documents.
  •  XPath is one of the locators supported by the selenium web driver.

 Types of XPath:

 absolute XPath

 relative XPath

9. How can we launch different browsers in the selenium web driver?

  •  By creating an instance of the driver of a particular browser

 WebDriver driver = new ChromeDriver();

10.What is the use of driver.get("url") and driver.navigate().to("url")command?

  •  Both driver. get("url") and driver.navigate().to("URL") commands are used to navigate to a URL passed as a parameter.

11. How can we type text in a textbox element using selenium?

  •  using the sendKeys() method we can type text in a textbox.

 WebElement text = driver.findElement(By.id("search"));

 text.sendKeys("suriya");

12. How we can clear a text written in a textbox?

  •  Using the clear() method we can delete the text written in a textbox.

 driver.findElement(By.id("elementLocator")).clear();

13. How to check a checkbox in selenium?

  •  the click() method used for clicking buttons or radio buttons can be used for checking checkboxes.

14. Difference between close and quit commands?

 driver.close() - used to close the current browser having focus.

 driver.quit() - used to close all the browser instances

15. Maximize browser window - driver.manage().window().maximiza();

16. Find the value - driver.findElement(By.id("locator")).getAttribute("value");

17. How to delete cookies in selenium?

 driver.manage().deleteAllCookies();

18. Double-click an element in selenium?

 Actions action = new Actions(driver);

 WebElement element = driver.findElement(By.id("elementid"));

 action.doubleClick(element).perform();

19. Right-click an element in selenium?

 Actions action = new Actions(driver);

 WebElement element = driver.findElement(By.id("elementid"));

 action.contextClick(element).perform();

20. How to fetch the current page URL in selenium?

 driver.getCurrentUrl();

21. How can we fetch the title of the page in selenium?

 driver.getTitle();

22. fetch the page source in selenium?

 driver.getPageSource();

Monday, June 20, 2022

JavaScriptExecutor in Selenium WebDriver

 JavaScript:

  •  JavaScript is a programming language that interacts with HTML DOM within the browser.

JavaScriptExecutor:

  •  JavaScript executor is an interface provided by Selenium that gives a mechanism to execute JavaScript through Selenium WebDriver.
  •  It provides two methods such as “executeScript” & “executeAsyncScript” to run JavaScript on the currently selected frame, window, or page.

Uses of JavaScriptExecutor:

  •  There are locators in Selenium WebDriver like ID, Class, XPath, etc., to work with elements on a web page.
  •  Sometimes these default Selenium locators may not work.
  •  JavaScriptExecutor is used to perform operations on a web page.
  •  JavascriptExecutor in Selenium enables the WebDriver to interact with HTML DOM within the browser.


1. Type Text in a Text Box

 JavascriptExecutor js = (JavascriptExecutor) driver;

 js.executeScript("document.getElementById('Email').value='suriya@gmail.com';");


2. To Click on a Button

 js.executeScript("document.getElementById('enter your element id').click();");


3. To refresh browser window using Javascript

 js.executeScript("history.go(0)");


4. To get the inner text of the entire webpage in Selenium

 String Text =  js.executeScript("return document.documentElement.innerText;").toString();

 System.out.println(Text);


5. To get the Title of our webpage

 String Text =  js.executeScript("return document.title;").toString();

 System.out.println(Text);


6. To get the URL of a webpage

 String Text =  js.executeScript("return document.URL;").toString();

 System.out.println(Text);


7. To perform Scroll on an application

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