2016-12-20 7 views
0

私はSeleniumでテストコードを書いています。私はこのような要素を待っている:私は期待要素が来ない場合はタイムアウトメッセージの代わりにカスタムメッセージを表示する必要がSelenium "TimeOut"ではなくカスタムメッセージを表示

WebDriverWait webDriverWait = new WebDriverWait(driver, 60); 
webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Link Text"))); 

私はwithMessage()メソッドを使用しましたが、この状況ではbuは機能しません。

webDriverWait.withMessage("message"); 

タイムアウトメッセージの代わりにカスタムメッセージを表示するにはどうすればよいですか。

答えて

0

timeOutExceptionをキャッチし、その時点で独自のカスタムエラーメッセージを提供する必要があります。次のようなもの:

try { 
    WebDriverWait webDriverWait = new WebDriverWait(driver, 60); 
    webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Link Text"))); 
} catch(TimeOutException e) { 
    System.out.println("[DEBUG] Could not find element in allowed time...") 
} 
+0

ありがとうございます。私はあなたが言ったようにして、それはおかしいです。 –

関連する問題