2017-02-09 5 views
0

私のメソッドが「タイムアウト例外」をキャッチしてコンソールに出力するのはなぜですか?私のメソッドが私の 'Timeout Exception'をキャッチしてコンソールに出力するのはなぜですか?

public void clickDrivingExperienceButton() throws Exception { 
    boolean test = this.wait.until(ExpectedConditions.elementToBeClickable(link_DrivingExperiences)).isEnabled(); 
    try { 
     if (test == true) { 
      link_DrivingExperiences.click(); 
     } 
     System.out.println("Successfully clicked on the driving experience button, using locator: " + "<" + link_DrivingExperiences.toString() + ">"); 
    }catch (TimeoutException e) { 
     System.out.println("WHY DONT I PRINT ANYTHING??????" + e.getMessage()); 
    }catch (Exception e) { 
     System.out.println("Unable to click on the Driving Experience Button, Exception: " + e.getMessage()); 
    } finally { 
     // final code here 
    } 
} 

enter image description here

答えて

0

ほとんどの場合、タイムアウト例外がthis.wait.until(ExpectedConditions.elementToBeClickable(link_DrivingExperiences)).isEnabled();の外に投げ、そしてあなたのtry-catchブロックは、そのライン内のtryブロックthis.wait.until入れ

+0

完全なスタックトレースを投稿すると、どのラインで例外が発生するのかが明確になります。 –

0

を囲みません。

例外メッセージは、要素がクリック可能であるのを待機していたときに例外が発生したことを既に示しています。例外は、2行目(wait.until)から来て、それがtry-catch内部ではないので

public void clickDrivingExperienceButton() throws Exception { 

    try { 
boolean test = this.wait.until(ExpectedConditions.elementToBeClickable(link_DrivingExperiences)).isEnabled(); 
     if (test == true) { 
      link_DrivingExperiences.click(); 
     } 
     System.out.println("Successfully clicked on the driving experience button, using locator: " + "<" + link_DrivingExperiences.toString() + ">"); 
    }catch (TimeoutException e) { 
     System.out.println("WHY DONT I PRINT ANYTHING??????" + e.getMessage()); 
    }catch (Exception e) { 
     System.out.println("Unable to click on the Driving Experience Button, Exception: " + e.getMessage()); 
    } finally { 
     // final code here 
    } 
} 
+0

何らかの理由でこれを行うと、設定時間は10秒となります。dosnt work – Gbru

+0

コードをクロスチェックします。文をtryの中に置いても問題はありません。今度は例外が捕捉されて印刷されます。 –

0

あなたtry-catchは、例外をキャッチされていません。

私はあなたの他の質問で扱った同じ問題の多くを持っています、https://stackoverflow.com/a/42120129/2386774、このコードでも修正することをお勧めします。


それは基本的にあなたが本当にあなたがログインしている限り多くをログに記録する必要はありません

public void clickDrivingExperienceButton() throws Exception 
{ 
    this.wait.until(ExpectedConditions.elementToBeClickable(link_DrivingExperiences)).click(); 
} 

以下でなければなりません。要素が正常にクリックされると、スクリプトが進行します。あなたのログを詰まらせるロギング、IMO。とにかくログにダンプされるため、例外をログに記録することもありません。通常、例外がスローされたときにスクリプトの処理を停止させたい場合は、処理がその影響を受けない限り行います。これは主にあなたのシナリオに依存するので、進めるべきかどうかの最終決定を下す必要があります。そうしないと、スローされた例外をどのように処理するかが決まります。

+0

もう一度、次の方法であなたがリストアップしました。方法を変更すると、メソッドをクリックしても成功することができませんでした。 – Gbru

+0

'wait.until()'の周りに 'try-catch'をスローし、' TimeoutException'を捕まえます。 – JeffC

関連する問題