Page 1 of 1
Best way to check if a Button is missing (C#).
Posted: Sat Nov 08, 2008 11:56 pm
by bebenin_s
Hello,
I am wondering if there is a way to check if the button exists on the Form.
I tried:
if (m_MyButton == null)
but I get Error CS0029: Cannot implicitly convert type 'Ranorex.Button' to 'bool'
Thanks!
Posted: Mon Nov 10, 2008 9:06 am
by Support Team
Hi,
Could you please clarify your request? I need to know how you're searching for a button object. In addition I'd have to know if you're using Ranorex V1.5 or Ranorex V2.0.
Would it be possible to provide me a more detailed code snippet?
best regard,
Christoph,
Ranorex Support Team
Posted: Mon Nov 10, 2008 2:25 pm
by bebenin_s
Hi, thanks for respond.
Here's the code (using Ranorex 1.5):
Form m_MessageBox = Application.FindFormTitle("FOO");
Button m_ButtonOk = m_MessageBox.FindButton("btnEnter");
if (m_ButtonOk == null)
{
........
}
else
{
.......
}
Would it be better to use Ranorex 2.0?
Thanks
Posted: Tue Nov 11, 2008 9:45 am
by Support Team
Your code works perfectly well for me. If button
m_ButtonOk is not found,
null is returned and the if branch is executed. Do you still get a compile error?
bebenin_s wrote:Would it be better to use Ranorex 2.0?
Ranorex 2.0 introduces new features that make automation a lot easier. Ranorex 2.0 code is more compact and even more readable than Ranorex 1.5 code. However, Ranorex 2.0 is not released, yet. There is a Technology Preview available, but it is not intended to be used in a productional environment due to stability issues.
Regards,
Alex
Ranorex Support Team
Posted: Tue Nov 11, 2008 2:22 pm
by bebenin_s
I know what happened. I used a single '=' instead of a double '=' in the IF statement.
Sorry for misinformation, it was very late.
Thank you very much.