findSingle compile error

Class library usage, coding and language questions.
BruceBalen
Posts: 9
Joined: Thu Jun 18, 2009 9:57 pm

findSingle compile error

Post by BruceBalen » Wed Jul 01, 2009 10:14 pm

Okay, this one makes absolutely no sense. I'm using a very simple instance of findSingle to locate a save button and click it like this:

Code: Select all

Button save = cmsForm.FindSingle(".//button[@accessiblename='Save']");
I get a compile error:

Cannot implicitly convert type 'Ranorex.Core.Element' to 'System.Windows.Forms.Button' (CS0029)

I've used this plenty of times in other solutions with no trouble. What gives?

BruceBalen
Posts: 9
Joined: Thu Jun 18, 2009 9:57 pm

Re: findSingle compile error

Post by BruceBalen » Wed Jul 01, 2009 10:19 pm

I think I fixed it. I had to change a namespace declaration:

using System.Windows.Forms;
to
using WinForms = System.Windows.Forms;

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: findSingle compile error

Post by Ciege » Wed Jul 01, 2009 10:58 pm

I think the compiler is getting confused as to what Button to use (the System.Windows.Forms.Button or the Ranorex.Button).

Easiest way around this is to change your code (not your using statement) to:

Code: Select all

Ranorex.Button save = cmsForm.FindSingle(".//button[@accessiblename='Save']");
I have actually made it a habit to prefix all Ranorex controls with Ranorex.* just so anyone in the future reading my code will have no ambiguities about what control I am referencing.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...