2

Could anyone say the difference use of the :

driver.manage().wait(long timeout)

and

WebDriverWait wait = new WebDriverWait(driver, WAIT_IN_SECONDS) 

(EXPLICIT WAIT) to understand my future reference.

Please pardon me the questions is silly for new bee of my self in automation.

Is it the simple form of the explicit wait?

MohanRaj
  • 81
  • 1
  • 2
  • 16
  • @DebanjanB Thanks for the quick reply.Actually, I don't believe this question is duplicate of the implicit wait and explicit wait as you say I hope the implicit wait is not defined By "driver.manage().wait(long time out)" it's defined by the "driver.manage().timeouts().implicitlyWait(some time in seconds)". – MohanRaj Jan 20 '18 at 13:06
  • @DebanjanB Here my doubt is the driver.manage().wait(time) it waits the time as the given time inside the wait. if it so then it's the simple form of the explicit wait? – MohanRaj Jan 20 '18 at 13:08

3 Answers3

1

driver.manage.wait(long timeout)

driver.manage.wait(long timeout) is actually the java.lang.Object.wait() method is from the java.lang.Object Class which causes the current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object or a specified amount of time has been elapsed. The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method. The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

Declaration

The declaration of java.lang.Object.wait() method is as follows :

public final void wait() throws InterruptedException
{
    //code logic
}

Parameters

timeout - the maximum time to wait in milliseconds.

Return Value

This method does not return a value.

Usage

In the one argument version, interrupts and spurious wakeups are possible so this method should always be used in a loop as follows :

 synchronized (obj) {
     while (<condition does not hold>)
         obj.wait();
     ... // Perform action appropriate to condition
 }

This method should only be called by a thread that is the owner of this object's monitor.

Exception

Throws :

  • InterruptedException : If another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
  • IllegalArgumentException : If the value of timeout is negative.
  • IllegalMonitorStateException : If the current thread is not the owner of the object's monitor.

Explicit Wait

Explicit Wait is a code block you define, configure and implement for the WebDriver instance to wait for a certain condition to be met before proceeding for the next line of code. There are some methods that helps us to implement ExplicitWait that will wait only as long as required. WebDriverWait in combination with ExpectedCondition is one of the way ExplicitWait can be achieved.

You can find a detailed discussion on Explicit Wait and it's implementation in the QA Replace implicit wait with explicit wait (selenium webdriver & java)


Answering this Question

obj.wait() have no relation with WebDriverWait. obj.wait() deals with the internal logic at thread-level where as WebDriverWait deals within the scope of HTML DOM.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
0

There are different ways to put wait in selenium. Implicit and Explicit and one more advance form of wait is Fluent Wait.

Swati001
  • 11
  • 4
0

Implicit wait

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

The implicit wait will tells the web driver to wait for a certain amount of time before it throws an exception.Implicit Wait time is applied to all the elements in the script.The disadvantage of implicit wait is that,even if the page and elements are loaded before the time unit, Webdriver holds the execution until that time is reached.

Explicit Wait

The explicit wait is used to tell the Web Driver to wait for certain conditions (Expected Conditions) or the maximum time exceeded before throwing an exception.The explicit wait is an intelligent kind of wait, but it can be applied only for specified elements. Explicit wait gives better options than that of an implicit wait as it will wait for dynamically loaded elements.

WebDriverWait wait = new WebDriverWait(driver, 40);

WebElement el = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("*xpath*")));
el.click();

Refer this link for more : https://www.guru99.com/implicit-explicit-waits-selenium.html

Sijin
  • 128
  • 9