所以我有这个通用函数,等待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]))
}
所以我的问题是如何在我的Exceptions
函数中添加另一个createFluentWait
,以便在超时之前避免Exception
? (忽略只获得2)
答案 0 :(得分:1)
您应该能够为createFluentWait
功能添加另一个.ignoring调用。您想忽略哪些其他例外?
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])
}
答案 1 :(得分:0)
您可以连结另一个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]))
}