Real Time Automation Testing Interview Questions- Part 2- Selenium

Selenium 

• What is the difference between findelement & findelements?

findelement will give the first appearance of that element which matches our locator, whereas findelements will give us list of all the elements which is present over the webpage and matching our locator. And if we don’t find the element findelement will give us nosuchelementexception whereas findelements will return NULL/Empty list.

• Can you tell me how you will handle multiple window in selenium.

We have windowhandle & windowhandles function for handling Multiple windows. Windowhandle will give the string value of only the active window that is open whereas windowhandles will give set of all the windows that are open in browser.

• How you will move from one window to another?

First we will check what all windows are open by using driver.getwindowhandles, to get set of opened windows , then use iterator to iterate over each of the pages and inside for loop will check like Current URL matches with the excepted page, if match then switch to that window by using driver.switchTo(Destination window) ,to return back to main parent window use driver.defaultwindow.

• Tell me the difference between Implicit & Explicit wait?

Implicit wait applies for all the elements and all the tests like if we give 10 sec of implicit wait it will wait for 10 sec for each element before giving nosuchelement exceptions. While Explicit wait can be applied for any particular step for which you want extra wait time so we can use explicit wait. We can use mix of both waits to depend on the situation of the step.

• Can you tell me some exceptions in selenium?

NoSuchElementException, NoSuchWindowException NoSuchframeException, StaleElementReferenceException, TimeoutException. 

• Can you tell me about StaleElementReferenceException?

Stale means old or decayed, here it sounds like element which was present on that page is no longer there or decayed. To handle this, we can refresh the webpage before pointing to that element. We can write script for waiting via explicit wait by writing expected condition.refresh. Or we can go with page object model in that we can over come this stale element exception.

• What do you mean by User Defined Exception?

User Defined Exception or custom exception is creating your own exception class and throws that exception using 'throw' keyword. This can be done by extending the class Exception. The keyword “throw” is used to create a new Exception and throw it to the catch block.

Comments

Popular posts from this blog

End-to-End Testing with Cypress using Cucumber precprocessor

Software Testing and Its Types