2012-09-25 179 views
0

測試我有一個功能 -繼續上一步失敗

private boolean selectFromDropDown(String locator, String value) { 
    try { 
     new Select(driver.findElement(By.xpath(locator))).selectByVisibleText(value); 
     return true; 
    } 
    catch (Error e) { 
      verificationErrors.append(e.toString()); 
      System.out.println("Could not find element"); 
      return false; 
     } 
} 

我希望函數返回true時動作可能要不回的一些消息,並繼續下一步。現在我收到一個錯誤 -

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Cannot locate element with text: Indi 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 16:53:24' 
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_07' 
Driver info: driver.version: unknown 
at org.openqa.selenium.support.ui.Select.selectByVisibleText(Select.java:147) 
at com.adobe.auto.testcases.utils.SeleniumTest.selectFromDropDown(SeleniumTest.java:89) 
at com.adobe.auto.testcases.utils.SeleniumTest.RunSeleniumTest(SeleniumTest.java:66) 
at com.adobe.auto.testcases.utils.Excel_Reader.runTest(Excel_Reader.java:653) 
at com.adobe.auto.testcases.utils.DriverFinal.main(DriverFinal.java:25) 

並且執行停止在那裏。

我需要做些什麼才能使其工作。

+0

愚蠢的問題,但我想會幫助很多!請編輯,以使其更好! –

回答

2

嘗試捕捉而不是錯誤的異常,它應該工作得很好。

錯誤來自java.lang.Error,異常來自java.lang.Exception。根據API 「錯誤」表示合理應用程序不應嘗試捕獲的嚴重問題。「 異常「表示合理的應用程序可能想要捕獲的條件。」

+0

這工作。傻我。 :) 但我們不能趕上錯誤呢? –

+0

我想你可以,但你會怎麼做呢?你真的需要它嗎? – Arek