2017-04-09

Implicit & Explicit Wait

##IMPLICIT WAIT##
Implicit wait is to inform IWebDriver to wait for certain amount of time for certain action in general.

Example:
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);



 Note:
SetScriptTimeout(), as well as ImplicitlyWait() and SetPageLoadTimeout() will be removed in future Selenium versions. In the source code you can see it has Obsolete annotation

[Obsolete("This method will be removed in a future version. Please set the AsynchronousJavaScript property instead.")]

Therefore you can change SetScriptTimeOut and PageLoadTimeout into following:

driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromMilliseconds(10);


Sleep Command
Rarely used, not recommended.
Thread.Sleep(6000);



##EXPLICIT WAIT##

In explicit wait, system waits for certain amount of time when condition requirement is met.

Example:
var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("www.google.com");
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
Assert.AreEqual(true, wait.Until(d => d.ElementIsPresent(By.ClassName("c2"))));
Assert.AreEqual(true, wait.Until(d => !d.ElementIsPresent(By.ClassName("c2"))));

No comments:

Post a Comment

Setup VNC on Ubuntu 20.04

  sudo apt update sudo apt install xfce4 xfce4-goodies sudo apt install tigervnc-standalone-server sudo apt install tightvncserver vncserver...