driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Is it possible to set '10' as variable so that it can be chabged dynamically? If possible how? Thank you!
An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0, meaning disabled. Once set, the implicit wait is set for the life of the session.
It is set for life of webdriver session.
Coming to your question Is it possible to set '10' as variable ?
Yes it's possible.
int a = 10;
driver.manage().timeouts().implicitlyWait(a, TimeUnit.SECONDS);
wrap this line in a method and pass the int args if you have static driver reference like this :
public void wdImplicitWait(int duration){
driver.manage().timeouts().implicitlyWait(duration, TimeUnit.SECONDS);
}
call it like this :
wdImplicitWait(5);
some web element interaction like click or sendkeys here
wdImplicitWait(3)
if your driver is not static then, make sure to pass driver instance reference
public void wdImplicitWait(int duration, WebDriver driver){
driver.manage().timeouts().implicitlyWait(duration, TimeUnit.SECONDS);
}
But there won't be any impact since it is set for entire life of webdriver
for the particular execution.
so calling implicitlyWait
again and again won't have any impact.
See what official doc says
If you are looking for a method that will set an implicitlyWait
accordingly to passed time duration it can be done as following:
public void setImplicitlyWait(Webdriver driver, int duration){
driver.manage().timeouts().implicitlyWait(duration, TimeUnit.SECONDS);
}
Depending on your actual project structure it's possible that you need to pass time duration only, do it will be like this:
public void setImplicitlyWait(int duration){
driver.manage().timeouts().implicitlyWait(duration, TimeUnit.SECONDS);
}
However it's not recommended to use implicitly waits, explicit waits should be used.
Also, if you still want to define implicitly wait it is normally defined once per driver instance i.e. for the entire test life.