I want to use fluent wait with selenium in scala. However I am not able to convert the below code into Scala. Please help me out.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(new Function<WebDriver, WebElement>()
{
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
});
When I use it in Scala, I get
@BrianMcCutchon - Hi. When I use this code in Scala, it gets converted to the following,
val wait = new FluentWait[WebDriver](driver).withTimeout(30, SECONDS).pollingEvery(5, SECONDS).ignoring(classOf[Nothing])
val foo = wait.until(new Nothing() {
def apply(driver: WebDriver): WebElement = driver.findElement(By.id("foo"))
})
In this code, val wait is not resolved. Moreover, Nothing seems meaningless
This code should be written with lambdas in both Java (8 and later) and Scala (2.12 to interoperate with Java interface
Function) unless you have a specific reason not to.Java:
Scala:
or
Also,
waitshould haveignoring(classOf[NoSuchElementException]), notNothing.