Selenium Interview Questions and Answers For Experienced

mytectra.com

1. What are the annotations used in TestNG?
@Test, @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, @BeforeClass, @AfterClass, @BeforeMethod, @AfterMethod, @BeforeGroups, @AfterGroups

2. What is a hub in Selenium Grid?
A hub is a server or a central point that controls the test executions on different machines.

3. How do you read data from excel?
FileInputStream fis = new FileInputStream (“path of excel file”);

Workbook wb = WorkbookFactory.create (fis);

Sheet s = wb.getSheet (“sheetName”)

String value = s.getRow (rowNum).getCell (cellNum).getStringCellValue ();

4. What is a node in Selenium Grid?
Node is the machine which is attached to the hub. There can be multiple nodes in Selenium Grid.

5. What are Soft Assert and Hard Assert in Selenium?
Soft Assert: Soft Assert collects errors during @Test Soft Assert does not throw an exception when an assert fails and would continue with the next step after the assert statement

Hard Assert: Hard Assert throws an Assert Exception immediately when an assert statement fails and test suite continues with next @Test

6. What are the verification points available in Selenium?
In Selenium IDE, we use Selenese Verify and Assert Commands as Verification points

In Selenium WebDriver, there is no built-in features for verification points. It totally depends on our coding style. some of the Verification points are

To check for page title

To check for certain text

To check for certain element (text box, button, drop down, etc.)

7.What is POM (Page Object Model)? What are its advantages?
Page Object Model is a design pattern for creating an Object Repository for web UI elements. Each web page in the application is required to have it’s own corresponding page class. The page class is thus responsible for finding the Web Elements in that page and then perform operations on those Web Elements. The advantages of using POM are: Allows us to separate operations and flows in the UI from Verification – improves code readability Since the Object Repository is independent of Test Cases, multiple tests can use the same Object Repository Reusability of code

8. How to launch a browser using Selenium WebDriver?
WebDriver is an Interface. We create Object of a WebDriver Interface.

<2.53 – no geckodriver

3.x – geckodriver for FF

To launch Firefox Driver:
WebDriver driver = new FirefoxDriver();

To launch Chrome Driver:
WebDriver driver = new ChromeDriver();

To launch Internet Explorer Driver:
WebDriver driver = new InternetExplorerDriver();

9. Is the FirefoxDriver a Class or an Interface? 
FirefoxDriver is a Java class, and it implements the WebDriver interface.

10. What is the super interface of WebDriver?
SearchContext.

11.What is Page Factory?
Page Factory gives an optimized way to implement Page Object Model. When we say it is optimized, it refers to the fact that the memory utilization is very good and also the implementation is done in an object oriented manner. Page Factory is used to initialize the elements of the Page Object or instantiate the Page Objects itself. Annotations for elements can also be created (and recommended) as the describing properties may not always be descriptive enough to differentiate one object from the other. The concept of separating the Page Object Repository and Test Methods is followed here also. Instead of having to use ‘FindElements’, we use annotations like: @FindBy to find WebElement, and initElements method to initialize web elements from the Page Factory class. @FindBy can accept tagName, partialLinkText, name, linkText, id, css, className & xpath as attributes. Since the Object Repository is independent of Test Cases, multiple tests can use the same Object Repository Reusability of code

12. 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 FirefoxDriver class.

13. We do create a reference variable ‘driver’ of type WebDriver
WebDriver driver = new FirefoxDriver();

instead of creating

FirefoxDriver driver = new FirefoxDriver();

What is the purpose of doing this way?

f 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.,

//FirefoxDriver driver = new FirefoxDriver();

ChromeDriver driver = new ChromeDriver();

driver.get(“http://www.google.com”);

WebDriver driver = new FirefoxDriver();

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

WebDriverException

TimeoutException

NoAlertPresentException

NoSuchWindowException

NoSuchElementException

StaleElementReferenceException

IllegalStateException

15.How to handle keyboard and mouse actions using Selenium?
We can handle special keyboard and mouse events by using Advanced User Interactions API. The Advanced User Interactions API contains the Actions and the Action Classes that are needed for executing these events. Most commonly used keyboard and mouse events provided by the Actions class are in the table below: Method Description clickAndHold() Clicks (without releasing) the current mouse location. dragAndDrop() Performs click-and-hold at the location of the source element, moves. source, target() Moves to the location of the target element, then releases the mouse

16. How To Login Into Any Site If It Is Showing Any Authentication Pop-Up For Username And Password?
To do this we pass username and password with the URL

http://username:[email protected]

e.g. http://admin:[email protected]

17. What are the types of waits available in Selenium WebDriver?
In Selenium we could see three types of waits such as Implicit Waits, Explicit Waits and Fluent Waits.

Implicit Waits –

Explicit Waits –

Fluent Waits –

PageLoadTimeOut

Thread.sleep() – static wait

18. What is Implicit Wait In Selenium WebDriver?
Implicit waits tell to the WebDriver to wait for a certain amount of time before it throws an exception. Once we set the time, WebDriver will wait for the element based on the time we set before it throws an exception. The default setting is 0 (zero). We need to set some wait time to make WebDriver to wait for the required time.

19. What is WebDriver Wait In Selenium WebDriver?
WebDriverWait is applied on a certain element with defined expected condition and time. This wait is only applied to the specified element. This wait can also throw an exception when an element is not found.

20.What are the different types of Drivers that WebDriver contains?
These are the different drivers available in WebDriver: FirefoxDriver InternetExplorerDriver ChromeDriver SafariDriver OperaDriver AndroidDriver IPhoneDriver HtmlUnitDriver

21. What is Fluent Wait In Selenium WebDriver?
FluentWait can define the maximum amount of time to wait for a specific condition and frequency with which to check the condition before throwing an “ElementNotVisibleException” exception.

22. How to input text in the text box using Selenium WebDriver?
By using sendKeys() method

WebDriver driver = new FirefoxDriver();

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

driver.findElement(By.xpath(“xpath”)).sendKeys(“test”);

23. How to input text in the text box without calling the sendKeys()?
// To initialize js object

JavascriptExecutor JS = (JavascriptExecutor)driver;

// To enter username

JS.executeScript(“document.getElementById(‘User’).value=test.com'”);

24. How to clear the text in the text box using Selenium WebDriver?
By using clear() method

WebDriver driver = new FirefoxDriver();

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

driver.findElement(By.xpath(“xpath_of_element1”)).sendKeys(“Software Testing Material Website”);

driver.findElement(By.xpath(“xpath_of_element1”)).clear();

25.How do you verify if the checkbox/radio is checked or not?
We can use isSelected () method.

Syntax – driver.findElement (By.xpath (“xpath of the checkbox/radio button”)).isSelected ();

If the return value of this method is true then it is checked else it is not.

26. How to get a text of a web element?
By using getText() method

27. How to get an attribute value using Selenium WebDriver?
By using getAttribute(value);

28.How to click on a hyperlink using Selenium WebDriver?

We use click() method in Selenium to click on the hyperlink

driver.findElement(By.linkText(“Software Testing Material Website”)).click();

29. How to submit a form using Selenium WebDriver?
We use “submit” method on element to submit a form

driver.findElement(By.id(“form_1”)).submit();

Alternatively, you can use click method on the element which does form submission

30. How to press ENTER key on text box In Selenium WebDriver?
To press ENTER key using Selenium WebDriver, We need to use Selenium Enum Keys with its constant ENTER.

driver.findElement(By.xpath(“xpath”)).sendKeys(Keys.ENTER);

Summary
Review Date
Reviewed Item
Excellent!! Selenium Interview Questions and answers for experienced Thank you mytectra.com for sharing.
Author Rating
51star1star1star1star1star
Share