Access Error (Visual Studio and WatiN)

I am using the WatiN testing tool with Visual Studio 2005. When I try to select a value from my list, I get an "access denied" error message.

+3
source share
3 answers

I often saw this with select lists when using the beta version of WatiN 2.0. Instead of using the aSelectList.Select (strText) parameter, it seems to work better when you do this:

ie.SelectList(Find.ById("MySelect")).Option(Find.ByText("Option 1")).Select(); 

This can also happen when you change an ASP.NET control that causes an automatic postback. The first change will be logged, but the next item that you are trying to access will cause a "Denied access" error because it is still trying to access the old page. In this case, you can try using ie.WaitForComplete (), but sometimes it is necessary:

 ie.SelectList(Find.ById("AutoPostBackSelect")).Option(Find.ByText("Option")).Select(); System.Threading.Thread.Sleep(200); //Sleep to make sure post back registers ie.WaitForComplete(); ie.SelectList(Find.ById("MySelect")).Refresh() ie.SelectList(Find.ById("MySelect")).Option(Find.ByText("Option 1")).Select(); 
+4
source

This is a mistake in the selection list, where if the list is not ready to accept input, and it can throw several types of exceptions. We solve this as follows:

 try { _domContainer.SelectList(_control.WatinAttribute).Focus(); _domContainer.SelectList(_control.WatinAttribute).Select(value); } catch (Exception e) { Console.WriteLine("Select list eception caught: " + e.Message + e.StackTrace); // we have tried once already and failed, so let wait for half a second System.Threading.Thread.Sleep(500); _domContainer.SelectList(_control.WatinAttribute).Select(value); } 

And yes, I know that swallowing all exceptions like this is usually bad, but if the exception happens again, it throws itself into the test code and the test fails.

+1
source

I noticed that this happens if you try to select a value that is already selected.

You can get around this with a preliminary check:

 if(_sel_ddlPeriodFromDay.GetValue("value")!="1") _sel_ddlPeriodFromDay.SelectByValue("1"); 

or perhaps use a catch attempt?

 try{_sel_ddlPeriodFromDay.SelectByValue("1");} catch{} 
+1
source

All Articles