WatiN UnauthorizedAccessException errors

你说的曾经没有我的故事 提交于 2019-12-10 11:27:43

问题


I am getting UnauthorizedAccessException errros when running any tests using NUnit and WatiN:

Test Test.IndexTests.Can_Do' failed: WatiN.Core.Exceptions.ElementNotFoundException : Could not find INPUT (hidden) or INPUT (password) or INPUT (text) or INPUT (textarea) or TEXTAREA element tag matching criteria: Attribute 'name' equals 'q' at http://www.google.com/ (inner exception: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)))
  ----> System.UnauthorizedAccessException : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
    at WatiN.Core.Element.get_NativeElement()
    at WatiN.Core.Element.GetAttributeValueImpl(String attributeName)
    at WatiN.Core.Component.GetAttributeValue(String attributeName)
    at WatiN.Core.Element.get_Id()
    at WatiN.Core.Element.get_IdOrName()
    at WatiN.Core.TextField.TypeText(String value)
    Class1.cs(23,0): at Tests.Can_Do()
    --UnauthorizedAccessException
    at mshtml.IHTMLElementCollection.tags(Object tagName)
    at WatiN.Core.Native.InternetExplorer.IEElementCollection.GetElementsByTag(String tagName)
    at WatiN.Core.NativeElementFinder.FindElementsByTag(String tagName)
    at WatiN.Core.NativeElementFinder.<FindElementByTags>d__0.MoveNext()
    at WatiN.Core.ElementFinder.FindFirst()
    at WatiN.Core.Element.FindNativeElement()
    at WatiN.Core.Element.get_Exists()
    at WatiN.Core.Element.<>c__DisplayClass9.<WaitUntilExistsOrNot>b__8()
    at WatiN.Core.UtilityClasses.TryFuncUntilTimeOut.Try[T](DoFunc`1 func)

0 passed, 1 failed, 0 skipped, took 43.44 seconds (NUnit 2.5.5).

I can't seem to find anything via google and was wondering if anyone has had a similar problem?

Cheers


回答1:


Try my answer to other question:

Try turning off IE's protected mode or add your site to trusted zone.

WatiN permissions problem when eval javascript code




回答2:


It can happen when the HTML is not entirely loaded You can add Sleep or add the wait for complete command

ie.WaitForComlete();

The best way is to catch the specific exception and try it again:

     try
     {
         //your code
     }
     catch (UnauthorizedAccessException)
     {

     }



回答3:


The solution for me was to uninstall the Trusteer Rapport browser security software that my bank offers. I had forgotten it was even installed.




回答4:


I had the same problem at random positions in the test. I was already running in the trusted zone.

Adding a

System.Threading.Thread.Sleep(200);

at each problem location "solved" the problem or at least its symptoms for me. At least I do not get the error anymore and am able to run the tests.

It seems to be a race condition somewhere.



来源:https://stackoverflow.com/questions/4120547/watin-unauthorizedaccessexception-errors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!