问题
The app is at certain view with submenus at the left and a list of items in the main content area. The user needs to select an item before clicking on any of the submenu to navigate to the submenu pages. If no item is selected and a submenu is clicked, the server is supposed to post an error to MVC and redirect to the original list page with the error message displayed on top of the page.
The test simply navigate to the list page, without selecting any item, immediately click on the submenu.
The following exception is caught by WatiN, if I use the try/catch block to eat the exception, the original list page would be displayed without the error message displayed on top. How can I tell WatiN to ignore the exception so that the error message would be displayed on top of the original list page, just as user would get by manually interact with the server w/o WatiN?
System.UnauthorizedAccessException was unhandled by user code
Message=Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Source=WatiN.Core
StackTrace:
at WatiN.Core.UtilityClasses.UtilityClass.TryFuncFailOver[T](DoFunc1 func, Int32 numberOfRetries, Int32 sleepTime)
at WatiN.Core.Native.InternetExplorer.IEElement.GetWithFailOver[T](DoFunc
1 func)
at WatiN.Core.Native.InternetExplorer.IEElement.GetAttributeValue(String attributeName)
at WatiN.Core.Element.GetAttributeValueImpl(String attributeName)
at WatiN.Core.Component.GetAttributeValue(String attributeName)
at WatiN.Core.Element.get_Enabled()
at WatiN.Core.Element.Click()
at ARMSAutomation.TestAnimals.NegativeTestNavigateToAnimalsPanels() in C:\ARMS\ARS\QA\Automation\ARMSAutomation\TestAnimals.cs:line 655
InnerException:
回答1:
I think this is a bug in WatiN which prevents the actual clicking on the button. That is why you still see your original page.
Try upgrading to the latest release (2.0.50) in which a lot of changes regarding the clicking on elements have been made.
HTH, Jeroen Lead dev WatiN.
来源:https://stackoverflow.com/questions/4951933/unauthorizedaccessexception-when-redirecting-to-a-new-page-with-the-error-displa