Clicking Custom Control

Oct 10, 2012 at 3:20 PM

Hello, I hope someone can help me out.  I'm trying to click a HtmlHyperlink, but it's not workinig.  I get an error either that the search is not valid or the object it's not an instance of an object.

I recorded the item with VS 2010.  I don't have access to the control's Id.  I've tried searching for several other properties (InnerText, TagInstance, TagName, FriendlyName, Href, and ControlDefinition).  for example:

bWin2.Get<CUITe.Controls.HtmlControls.

CUITe_HtmlHyperlink>("InnerText=Log In To Your Account"

).Click();

No luck....

Coordinator
Oct 10, 2012 at 3:24 PM

Do you have some sample html and coded ui test code that can reproduce the problem?

What is the complete error with stack trace?

What is the code that the Visual Studio Coded UI Test Recorder generates?

Are there any issues during playback of the code that the Visual Studio Coded UI Test creates?

Oct 10, 2012 at 3:39 PM

1.  html source:

 

<div class

="option registered-user">

 

<p>
 

 

<a class="colored-button" href="/login">Log In To Your Account</a>
 

 

<p class="description">If you already have an account created, please log in to access your product related information.</p>
 

 

</p>
 

 

</div>

 

 

 

2.  Error:  UITestControlNotAvailableException.

 

Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.AccWrapper.GetAccWrapperFromWindow(IntPtr windowHandle)
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.MsaaElement..ctor(IntPtr win32Handle)
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.MsaaUtility.GetWin32TopElement(MsaaElement element)
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.MsaaElement.get_TopLevelElement()
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.MsaaElement.get_IsTopLevelElement()
Microsoft.VisualStudio.TestTools.UITest.Extension.Msaa.MsaaElement.get_QueryId()
Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMapUtil.FillPropertyFromUIElement(UIObject obj, IUITechnologyElement element)
Microsoft.VisualStudio.TestTools.UITesting.ALUtility.GetSpecializedType(UITestControl uiControl)
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetSpecializedControl(UITestControl uiControl)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.SearchTopLevelWindow(ISearchArgument topLevelSearchArg, String topLevelElementQueryId)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetTitleUpdatedTopLevelWindow(ISearchArgument topLevelSearchArg, String queryId, IList`1 windowTitles)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetTopLevelElement(Boolean useCache, Boolean useCacheOnly, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(Boolean useCache, ISearchArgument searchArg)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search(ISearchArgument searchArg)
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.Find()
Microsoft.VisualStudio.TestTools.UITesting.IEBrowserService.Locate(PropertyExpressionCollection searchProperties, PropertyExpressionCollection filterProperties, Boolean findAll)
Microsoft.VisualStudio.TestTools.UITesting.IEBrowserFactory.Locate(PropertyExpressionCollection searchProperties, PropertyExpressionCollection filterProperties)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.SearchTopLevelWindow(ISearchArgument topLevelSearchArg, String topLevelElementQueryId)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.SearchUsingMultipleTitles(ISearchArgument topLevelSearchArg, QueryId topLevelQueryId, IList`1 windowTitles)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.SearchUsingMultipleTitles(ISearchArgument topLevelSearchArg, QueryId topLevelQueryId, IList`1 windowTitles)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetTitleUpdatedTopLevelWindow(ISearchArgument topLevelSearchArg, String queryId, IList`1 windowTitles)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetTopLevelElement(Boolean useCache, Boolean useCacheOnly, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetUITestControlRecursive(Boolean useCache, Boolean alwaysSearch, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetUITestControlRecursive(Boolean useCache, Boolean alwaysSearch, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetUITestControlRecursive(Boolean useCache, Boolean alwaysSearch, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetUITestControlRecursive(Boolean useCache, Boolean alwaysSearch, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(Boolean useCache, ISearchArgument searchArg)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search(ISearchArgument searchArg)
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindControlIfNecessary()
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.Click(MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinates)
Microsoft.VisualStudio.TestTools.UITesting.Mouse.ClickImplementation(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate)
Microsoft.VisualStudio.TestTools.UITesting.Mouse.ClickImplementationWrapper(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate)
Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(UITestControl control, Point relativeCoordinate)
MyStarkey.UIMap1Classes.UIMap1.RecordedMethod1() in C:\Users\closl\Documents\Visual Studio 2010\Projects\MyStarkey\MyStarkey\UIMap1.Designer.cs: line 49
MyStarkey.CodedUITest2.AddProducts() in C:\Users\closl\Documents\Visual Studio 2010\Projects\MyStarkey\MyStarkey\CodedUITest2.cs: line 55

3.  

RecordedMethod1 - Use 'RecordedMethod1Params' to pass parameters into this method.

 

public void

RecordedMethod1()

{

 

#region

Variable Declarations

BrowserWindow uIGoogleWindowsInterneWindow = this

 

 

.UIGoogleWindowsInterneWindow;

HtmlHyperlink uILogInToYourAccountHyperlink = this

 

 

.UIGoogleWindowsInterneWindow.UIMyWebPagesDocument.UIBlocksystemmainPane.UILogInToYourAccountHyperlink;

 

#endregion 

 

// Go to web page 'http://www.google.com/' using new browser instance

BrowserWindow googlecomBrowser = BrowserWindow.Launch(new System.Uri(this

 

.RecordedMethod1Params.Url));

// Go to web page 'http://www.mystarkey.com/'

 

uIGoogleWindowsInterneWindow.NavigateToUrl(

new System.Uri(this

.RecordedMethod1Params.UIGoogleWindowsInterneWindowUrl));

// Click 'Log In To Your Account' link

Mouse.Click(uILogInToYourAccountHyperlink, new Point

(91, 17));

}

4.  Yes, the code crashes because the control is not available.

Oct 10, 2012 at 3:43 PM

I forgot to mention that I looked at the discussion for HTML_Custom... I was gonna use that, but It wasn't listed under Cuite.Controls.HtmlControls.  I downloaded 1.05... However, the version that's listed under properties is 1.04.  I don't know if that's the issue or not.

Oct 10, 2012 at 6:48 PM

Update:  I added the CUITe project to my project, so I could step through the code.  I believe the problem is in CUITeBrowserWindow.  In Get(), the line that calls Activator.CreateInstance, brings back an object, but all in the information within the object is not availalbe.  I think this is where the problem is.  I can send a snapshot of what I mean if you'd like.

Coordinator
Oct 11, 2012 at 12:05 AM

If there is an issue when playing back the code generated using the Visual Studio Coded UI Test Recorder, and the code is similar when using CUITe, then the issue would likely still occur.

What are the search properties defined for UIGoogleWindowsInterneWindow.UIMyWebPagesDocument.UIBlocksystemmainPane.UILogInToYourAccountHyperlink?

The latest source code can be found by clicking on the "Source Code" link.

I highly recommend using the latest source code.

It could also be possible the issue might be with how bWin2 is defined.

If you can provide the complete CUITe code, that will help me to provide you with more accurate feedback.

The html hyperlink element (<a/>) is not really considered a custom control.

Oct 11, 2012 at 1:15 PM
Hello Icnocop,

Thank you for your reply!! I just learned of CUITe this week. I love the concept and really hope that I can use it. The Maps are what drove me nuts about automated testing with VS.

The code I tried below were samples from the Get Started document and from discussion threads. I was mainly just trying to get something to work.

I appreciate your help!

The properties generated for the UILogInToYourAccountHyperlink were (blank where Microsoft didn't specify a value):

ControlType = Hyperlink
TechnologyName = Web
Id =
Name =
TagName = A
Target =
Inner Text = Log In To Your Account

CUITe.Controls.HTMLControls.CUITe_BrowserWindow.Launch(http://www.mystarkey.com);
CUITe.Controls.HTMLControls.CUITe_BrowserWindow bWin2 = new CUITe.Controls.HTMLControls.CUITe_BrowserWindow("MyStarkey2");

//Tried this first
CUITe.Controls.HTMLControls.CUITe_HtmlCustom custom = bWin2.Get<CUITe.Controls.HtmlControls.CUITe_HtmlCustom>("A");
custom.Click();

// tried this second
CUITe.Controls.HTMLControls.CUITe_HtmlHyperlink link = new CUITe.Controls.HtmlControls.CUITe_HtmlHyperlink();
link.Click();



From: [email removed]
To: [email removed]
Date: Wed, 10 Oct 2012 17:05:54 -0700
Subject: Re: Clicking Custom Control [cuite:398833]

From: icnocop
If there is an issue when playing back the code generated using the Visual Studio Coded UI Test Recorder, and the code is similar when using CUITe, then the issue would likely still occur.
What are the search properties defined for UIGoogleWindowsInterneWindow.UIMyWebPagesDocument.UIBlocksystemmainPane.UILogInToYourAccountHyperlink?
The latest source code can be found by clicking on the "Source Code" link.
I highly recommend using the latest source code.
It could also be possible the issue might be with how bWin2 is defined.
If you can provide the complete CUITe code, that will help me to provide you with more accurate feedback.
The html hyperlink element () is not really considered a custom control.
Read the full discussion online.
To add a post to this discussion, reply to this email (cuite@discussions.codeplex.com)
To start a new discussion for this project, email cuite@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Coordinator
Oct 11, 2012 at 3:13 PM

Just as I suspected, there is an issue on how you initialized bWin2.

Please try this:

 

CUITe_BrowserWindow bWin2 = CUITe_BrowserWindow.Launch(http://www.mystarkey.com);

CUITe_HtmlHyperlink hyperlink = bWin2.Get<CUITe_HtmlHyperlink>("InnerText=Log In To Your Account");

hyperlink.Click();
Oct 11, 2012 at 4:46 PM
Hello again, Thank you so much for your input. It's a big help to me getting started.

The first line causes the project not to build. It expects ")". when I put the site in quotes then I had a another problem: "Cannot implicitly convert type 'Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow' to 'CUITe.Controls.HtmlControls.CUITe_BrowserWindow'.

closl

From: [email removed]
To: [email removed]
Date: Thu, 11 Oct 2012 08:14:04 -0700
Subject: Re: Clicking Custom Control [cuite:398833]

From: icnocop
Just as I suspected, there is an issue on how you initialized bWin2.
Please try this:

CUITe_BrowserWindow bWin2 = CUITe_BrowserWindow.Launch(http://www.mystarkey.com);

CUITe_HtmlHyperlink hyperlink = bWin2.Get<CUITe_HtmlHyperlink>("InnerText=Log In To Your Account");

hyperlink.Click();
Read the full discussion online.
To add a post to this discussion, reply to this email (cuite@discussions.codeplex.com)
To start a new discussion for this project, email cuite@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Coordinator
Oct 11, 2012 at 6:21 PM

Sorry about that, I didn't test it myself.

Please try:

CUITe_BrowserWindow bWin2 = CUITe_BrowserWindow.Launch("http://www.mystarkey.com", "My Web Pages");

CUITe_HtmlHyperlink hyperlink = bWin2.Get<CUITe_HtmlHyperlink>("InnerText=Log In To Your Account");

hyperlink.Click();


Oct 11, 2012 at 6:47 PM
Edited Oct 11, 2012 at 6:50 PM
Hello again,

Did you happen to test that from your end? I still get the same exception.

Test method MyStarkey.CodedUITest2.AddProducts threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.

Thank you

From: [email removed]
To: [email removed]
Date: Thu, 11 Oct 2012 11:21:14 -0700
Subject: Re: Clicking Custom Control [cuite:398833]

From: icnocop
Sorry about that, I didn't test it myself.
Please try:
CUITe_BrowserWindow bWin2 = CUITe_BrowserWindow.Launch("http://www.mystarkey.com", "My Web Pages");

CUITe_HtmlHyperlink hyperlink = bWin2.Get<CUITe_HtmlHyperlink>("InnerText=Log In To Your Account");

hyperlink.Click();

--- It crashes on the "WaitForReady" line in the Click()

 

Read the full discussion online.
To add a post to this discussion, reply to this email (cuite@discussions.codeplex.com)
To start a new discussion for this project, email cuite@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Coordinator
Oct 13, 2012 at 1:32 AM

It works fine for me.

What is the complete stack trace?

Oct 15, 2012 at 2:34 PM
Hello, Here's the stack trace requested.

Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow..ctor(UITestControl control)
Microsoft.VisualStudio.TestTools.UITesting.BrowserWindowPropertyProvider.GetPropertyValue(UITestControl uiTestControl, String propertyName)
Microsoft.VisualStudio.TestTools.UITesting.UITestPropertyProvider.GetPropertyValueWrapper(UITestControl uiControl, String propertyName)
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyValue(String propertyName)
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetProperty(String propertyName)
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyInternal[T](String propertyName)
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.get_WindowHandle()
Microsoft.VisualStudio.TestTools.UITesting.IEBrowserService.Locate(PropertyExpressionCollection searchProperties, PropertyExpressionCollection filterProperties, Boolean findAll)
Microsoft.VisualStudio.TestTools.UITesting.IEBrowserFactory.Locate(PropertyExpressionCollection searchProperties, PropertyExpressionCollection filterProperties)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.SearchTopLevelWindow(ISearchArgument topLevelSearchArg, String topLevelElementQueryId)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetTitleUpdatedTopLevelWindow(ISearchArgument topLevelSearchArg, String queryId, IList`1 windowTitles)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetTopLevelElement(Boolean useCache, Boolean useCacheOnly, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetUITestControlRecursive(Boolean useCache, Boolean alwaysSearch, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetUITestControlRecursive(Boolean useCache, Boolean alwaysSearch, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(Boolean useCache, ISearchArgument searchArg)
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search(ISearchArgument searchArg)
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindControlIfNecessary()
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlReady(Int32 millisecondsTimeout)
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlReady()
CUITe.Controls.CUITe_ControlBase`1.Click() in C:\Users\closl\Downloads\CUITe Source\CUITe\Controls\CUITe_ControlBase.cs: line 207
MyStarkey.CodedUITest2.AddProducts() in C:\Users\closl\Documents\Visual Studio 2010\Projects\MyStarkey\MyStarkey\CodedUITest2.cs: line 65



From: [email removed]
To: [email removed]
Date: Fri, 12 Oct 2012 18:33:03 -0700
Subject: Re: Clicking Custom Control [cuite:398833]

From: icnocop
It works fine for me.
What is the complete stack trace?
Read the full discussion online.
To add a post to this discussion, reply to this email (cuite@discussions.codeplex.com)
To start a new discussion for this project, email cuite@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Coordinator
Oct 15, 2012 at 9:41 PM

What does the code look like in CodedUITest2.cs around line 65?