Selenium Question Din

You might also like

You are on page 1of 4

Selenium

1) Why do we get exceptions when interacting with web elements ?


Reasons :
1. The Element we try to interact / find is not at all present in the DOM .
2. Element is present in DOM but NOT visible .
3. Element is present in DOM but NOT interactable ( enabled )

2)What to do in this case?


Known solution for us: Thread.sleep(5000).
3)Why to use Selenium Waits over thread.sleep()?
4)What are selenium waits?
5)Types of Waits in Selenium ->
Implicit.
Explicit.
Fluent.
6)Which one is better? Pros and cons

Explicit wait:

It allows us to command the webdriver to wait until several


conditions are met.

How to use:

1.Create WebDriverWait instance (Object) => driver, seconds


2. wait until (condition to be met)

Some condition

1.elementToBeClickable()
2.elementToBeSelected ()
3.presenceOfElementLocated()
4.textToBePresent InElement ()
5. alertIsPresent() and so on.....

how is it better from implicit wait:

(IW) only checks the presence of element on (DOM)WebPage that’s all.


if elements are hidden or any other condition
then it will not handle and it will fail the script.

but here, we can handle more predefined conditions.

If there is a network issue and if ur application always performs slow,


then, IW is better.

You might also like