2012-09-25 125 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