Strange timeout with ScalaTest's Selenium DSL Strange timeout with ScalaTest's Selenium DSL selenium selenium

Strange timeout with ScalaTest's Selenium DSL


It is clear that the textField(name("firstName")).value = "Steve" ends up calling the WebElement as you have found out.Since the issue in the op is happening where ever web elements are involved (which in turn implies that webdriver is involved), I think it is safe to assume that the issue is related to the implicit wait on the Web driver.

implicitlyWait(Span(0, Seconds))

The above should ideally fix the issue. Also, making implicit wait to be 0 is a bad practice. Any web page might have some loading issues. The page load is handled by Selenium outside its wait conditions. But slow element load (may be due to ajax calls) could result in failure. I usually keep 10 seconds as my standard implicit wait. For scenarios which require more wait, explicit waits can be used.

def implicitlyWait(timeout: Span)(implicit driver: WebDriver): Unit = {driver.manage.timeouts.implicitlyWait(timeout.totalNanos, TimeUnit.NANOSECONDS)}

Execution Flow:

name("firstName") ends up having value as Query {Val by = By.className("firstName") }.

def name(elementName: String): NameQuery = new NameQuery(elementName)case class NameQuery(queryString: String) extends Query { val by = By.name(queryString) }

Query is fed to the textField method which calls the Query.webElement as below.

def textField(query: Query)(implicit driver: WebDriver, pos: source.Position): TextField = new TextField(query.webElement)(pos)sealed trait Query extends Product with Serializable {    val by: By    val queryString: String    def webElement(implicit driver: WebDriver, pos: source.Position = implicitly[source.Position]): WebElement = {      try {        driver.findElement(by)      }      catch {        case e: org.openqa.selenium.NoSuchElementException =>          // the following is avoid the suite instance to be bound/dragged into the messageFun, which can cause serialization problem.          val queryStringValue = queryString          throw new TestFailedException(                     (_: StackDepthException) => Some("WebElement '" + queryStringValue + "' not found."),                     Some(e),                     pos                   )      }    }  }


I don't know ScalaTest's specifics, but such strange timeouts usually occur when you're mixing up implicit and explicit waits together.

driver.findElement uses implicit waits internally. And depending on specified explicit waits timeout, you may face with summing both together.

Ideally, implicit waits should be set to 0 to avoid such issues.