Skip to content

ValueElement's value_= can fail with HtmlUnitDriver #10

@DaniRey

Description

@DaniRey

As part of scalatest/scalatest@1529062 the implementation of ValueElement's value_= changed from

    def value_=(value: String): Unit = {
      underlying.clear()
      underlying.sendKeys(value)

to

    def value_=(value: String)(implicit driver: WebDriver): Unit = {
      underlying.clear()

      driver match {
        case executor: JavascriptExecutor => executor.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", underlying, "value", value)
        case _ => underlying.sendKeys(value)
      }
      //underlying.setAttribute("value", value)
      //underlying.sendKeys(value)
    }

The new implementation fails when using HtmlUnitDriver with JavaScript disabled.

Exception encountered when invoking run on a nested suite - Javascript is not enabled for this HtmlUnitDriver instance
java.lang.UnsupportedOperationException: Javascript is not enabled for this HtmlUnitDriver instance
	at org.openqa.selenium.htmlunit.HtmlUnitDriver.getPageToInjectScriptInto(HtmlUnitDriver.java:942)
	at org.openqa.selenium.htmlunit.HtmlUnitDriver.executeScript(HtmlUnitDriver.java:882)
	at org.scalatestplus.selenium.WebBrowser$ValueElement.value_$eq(WebBrowser.scala:1927)
	at org.scalatestplus.selenium.WebBrowser$ValueElement.value_$eq$(WebBrowser.scala:1922)
	at org.scalatestplus.selenium.WebBrowser$EmailField.value_$eq(WebBrowser.scala:1960)
...

We could work around this issue (unic/ScalaWebTest#108) by changing our code from

      emailField(username_fieldname).value = username

to

      emailField(username_fieldname).underlying.sendKeys(username)

Before doing so, we would like to understand the motivation behind this change. Maybe there is a better solution, either for scalatestplus-selenium or for scalawebtest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions