david hol
david hol

Reputation: 1280

Selenium: how to ignore more then 2 exception

So i have this generic function that wait for my element base on ExpectedCondition:

def findMyElement(expectedCondition: (By) => ExpectedCondition[WebElement], by: By, timeOut: Long): WebElement = {

    createFluentWait(timeOut).until(expectedCondition(by))
    driver.findElement(by)
  }

 def createFluentWait(timeOut: Long): FluentWait[WebDriver] = {

    new FluentWait[WebDriver](driver)
      .withTimeout(timeOut, TimeUnit.SECONDS)
      .pollingEvery(1, TimeUnit.SECONDS)
      .ignoring(classOf[NoSuchElementException], (classOf[StaleElementReferenceException]))
  }

So my question is how to add another Exceptions to my createFluentWait function in order to avoid Exception before time out ? (ignoring gets only 2)

Upvotes: 1

Views: 612

Answers (2)

Graham Russell
Graham Russell

Reputation: 1047

You should be able to add another .ignoring call to your createFluentWait function. Which other exceptions were you wanting to ignore?

def createFluentWait(timeOut: Long): FluentWait[WebDriver] = {

    new FluentWait[WebDriver](driver)
        .withTimeout(timeOut, TimeUnit.SECONDS)
        .pollingEvery(1, TimeUnit.SECONDS)
        .ignoring(classOf[NoSuchElementException])
        .ignoring(classOf[StaleElementReferenceException])
        .ignoring(classOf[SomethingElseException])
}

Upvotes: 1

Guy
Guy

Reputation: 50809

You can concat another ignoring

def createFluentWait(timeOut: Long): FluentWait[WebDriver] = {

    new FluentWait[WebDriver](driver)
        .withTimeout(timeOut, TimeUnit.SECONDS)
        .pollingEvery(1, TimeUnit.SECONDS)
        .ignoring(classOf[NoSuchElementException, (classOf[StaleElementReferenceException]))
        .ignoring(classOf[NullPointerException, (classOf[StaleElementReferenceException]))
}

Upvotes: 0

Related Questions