Implicit Wait :
Implicit Wait is the way to configure the WebDriver instance to poll the HTML DOM for a configured amount of time when it tries to find an element or find a group/collection of elements if they are not immediately available. As per the current W3C specification the default time is configured to 0
. We can configure the time for the Implicit Wait any where within our script/program and can reconfigure it as per our necessity. Once we set Implicit Wait it will be valid for the lifetime of the WebDriver instance.
References
A couple of references:
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. WebDriverWait along with certain methods/clauses of ExpectedConditions is one way to implement Explicit Wait.
References
A couple of references:
Getting Granular :
As per your query ...Let say myDynamicElement is visible at 6th second, So in both the cases driver will wait till 6th seconds and control will move to the consecutive written statement...
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Implicit Wait would poll the DOM Tree for the entire 10 secs irrespective of whether myDynamicElement (or multiple elements matching your locator) is visible at 4th / 6th / 8th second. So, in this case, your script gets delayed by 4 secs.
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement myDynamicElement= wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
Explicit Wait would wait for maximum of 10 secs for the element someid
to turn clickable (Displayed and Enabled). The WebElement is returned back as soon as the ExpectedConditions is met. If the ExpectedConditions is not met for the entire duration of the configured timeline, you see the proper Exception.