2016-05-22 4 views
1

は、だから私はExpectedConditionに私の要素のベースを待ち、この汎用的な機能を持っている:セレン:無視する方法より2例外その後、

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])) 
    } 

だから私の質問はするために私のcreateFluentWait関数に別のExceptionsを追加する方法でありますタイムアウトする前にExceptionを避ける?

答えて

1

をCONCATすることができます。あなたが無視したい他の例外はどれですか?

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]) 
} 
+0

複数の例外を追加するとよいですか?またはそれを避けるために多分?私はタイムアウトに達するまで試してみたい、ElementNotVisibleExceptionとNoSuchElementExceptionも無視したい。 –

+0

何が例外になっているのか、なぜ起こっているのか、それが予期しているかどうかによります。私は、 'NoSuchElementException'と' StaleElementReferenceException'が私が使用する唯一の2つであることがよくあります。 –

+0

例外の注文にも問題はありますか? –

0

(無視してはわずか2を取得します)あなたは、あなたのcreateFluentWait関数に別の.ignoring呼び出しを追加することができる必要があり、別の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])) 
} 
関連する問題