You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
privatedefasJsString(text: String):String= {
valsb=newStringBuilder
sb.append("'")
text.foreach {
case'\''=> sb.append("\\'")
case'\\'=> sb.append("\\\\")
case'\n'=> sb.append("\\n")
case'\r'=> sb.append("\\r")
case'\t'=> sb.append("\\t")
case c => sb append c
}
sb.append("'")
sb.toString()
}
implicitclassWebElementLocalExt(privatevalself:WebElement) extendsAnyVal {
privatedefcurrentValue():String=
self.getAttribute("value")
defquickSetTextIfNeeded(text: String)(implicitd: WebDriver):Unit=if (text != currentValue())
quickSetText(text)
defquickSetText(text0: String)(implicitd: WebDriver):Unit=if (text0.isEmpty)
self.clear()
else {
// React will only ingest the new value when it receives an event - just modifying the dom via JS will go// ignored by React. Therefore we set all but the last character using JS then use a real event for the last// char. This also has the nice effect of supporting a carriage-return at the end of the text argument to trigger// form submission.valtext= text0.replace("\r", "")
valn= text.reverseIterator.takeWhile(_ =='\n').size +1valloc= self.getLocation
valx=s"${loc.x}-window.scrollX+1"valy=s"${loc.y}-window.scrollY+1"valinit= text.dropRight(n)
vallast= text.takeRight(n)
val (lastText, lastOther) =if (last.endsWith("\n")) (last.dropRight(1), "\n") else (last, "")
valcmd=s"document.elementFromPoint($x,$y).value=${asJsString(init)}"// println(s"${asJsString(init)} | ${asJsString(lastText)} | ${asJsString(lastOther)}")// println(cmd)// Step 1: Fast!if (currentValue() !=* init) {
d.executeJsOrThrow(cmd)
assert(currentValue() ==* init) // Without this, the value here can be overwritten by the steps below
}
// Step 2: Send 1 textual char without \n so that the app processes the expected event
self.sendKeys(Keys.END+ lastText)
assert(currentValue() ==* (init + lastText))
// Step 3: Send the non-text key// This needs to be separate from the previous step else ~2% of the time, the update is missedif (lastOther.nonEmpty)
self.sendKeys(lastOther)
}
The text was updated successfully, but these errors were encountered:
This is much faster
The text was updated successfully, but these errors were encountered: