How to invoke the default action of a table row element

Ask general questions here.
User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

How to invoke the default action of a table row element

Post by Ciege » Tue May 19, 2009 11:01 pm

I have a DevExpress table that some rows have an AccessibleDefaultAction of Expand or Collapse detail. This actually opens another table under this row.

No I can search the parent table and for each row I can check what the AccessibleDefaultAction is:

Code: Select all

Ranorex.Table HDTable = RanorexFormName.FindSingle("/form[@controlname='frmMainDialog']/element/form[@controlname='CostItemRegisterForm']/container[@controlname='pnlMain']/*/table", 10000);

foreach (Ranorex.Row row in HDTable.Rows)
{
  string strDefaultAction = row.Element.GetAttributeValue("AccessibleDefaultAction").ToString();
  Report.Info("Accessible Actions: " + strDefaultAction);
  if (strDefaultAction == "Expand detail")
  {
      //Invoke Action needs to go here
  }
}
Now, how can I invoke this default action? The row object that I now have control over does not have a DoDefaultAction() method associated with it.

I cannot click the or double click the row or cell because that does a different action than Expanding the detail table.

Thanks...

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

Post by Ciege » Tue May 19, 2009 11:50 pm

I tried the following code but it failed:

Code: Select all

row.Element.InvokeAction(row.Element.GetAttributeValue("AccessibleDefaultAction").ToString());
Exception text:

Code: Select all

[2009/05/19 15:48:53.540][Failure][User]: Ranorex.ActionFailedException: Action'Expand detail' failed on element '{Row:Row 8}'. ---> System.NotSupportedException: The operation is not supported.
   at Ranorex.Plugin.MsaaFlavorElement.InvokeAction(Element element, String name, Object[] args)
   at Ranorex.Core.Element.InvokeAction(String name, Object[] args)
   --- End of inner exception stack trace ---
   at Ranorex.Core.Element.InvokeAction(String name, Object[] args)
   at H_ReportsTest.Program.Main(String[] args) in C:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\H$ReportsTest\H$ReportsTest\Program.cs:line 94

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Wed May 20, 2009 8:33 am

I recommend using the corresponding adapter instead of calling the GetAttributeValue/InvokeAction methods directly on the Element, since the adapters are type-safe and not as error-prone as writing attribute/action names as strings.
You can see which adapter to use in RanorexSpy: each attribute in the General tab is listed in a category that is named like the adapter that provides easy access to the attribute/action. You can then convert between adapters (or from Element to an adapter) using the As<AdapterType>() method.

In your example, you should use the Accessible adapter:

Code: Select all

foreach (Ranorex.Row row in HDTable.Rows)
{
  Accessible accRow = row.As<Accessible>();
  string strDefaultAction = accRow.DefaultAction;
  Report.Info("Accessible Actions: " + strDefaultAction);
  if (strDefaultAction == "Expand detail")
  {
    accRow.DoDefaultAction();
  }
}
Regards,
Alex
Ranorex Support Team

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

Post by Ciege » Wed May 20, 2009 7:03 pm

OK, I tried using the code you provided but I get the following compile error:

Code: Select all

The type or namespace name 'Accessible' could not be found (are you missing a using directive or an assembly reference?)
I could not seem to find the right combination of keywords to get a reference to Accessible. I am "using" Ranorex and Ranorex.Core.

Also, under the Overview tab I have the following details:

Code: Select all

General
Enabled - True
Valid - True
Visible - True

Row
Index - <blank>
Selected - False

Accessible
AccessibleDefaultAction - Expand detail
AccessibleDescription - <blank>
AccessibleHelp  - <blank>
AccessibleHelpTopic  - <blank>
AccessibleKeyboardShortcut  - <blank>
AccessibleName - Row11
AccessibleRole - Row
AccessibleState - ReadOnly, Collapsed, Focusable, Selectable
AccessibleValie - <lots of data>

So I am assuming that the AdapterType would be Row, correct?

Now, how do I get around the compile error on the keyword Accessible?

Thanks...

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

Post by Ciege » Wed May 20, 2009 7:27 pm

OK, I found the compile issue. I did not have a reference to Ranorex.Plugin.MSAA Once I added that reference it compiled fine.

However, I get this exception when it hits the accRow.DoDefaultAction() line. I have used the code you provided exactly. Need I change somthing in it?

Code: Select all

[2009/05/20 11:20:30.759][Failure][User]: Ranorex.ActionFailedException: Action'accessibledodefaultaction' failed on element '{Row:Row 9}'. ---> System.NotSupportedException: The operation is not supported.
   at Ranorex.Plugin.MsaaFlavorElement.InvokeAction(Element element, String name, Object[] args)
   at Ranorex.Core.Element.InvokeAction(String name, Object[] args)
   --- End of inner exception stack trace ---
   at Ranorex.Core.Element.InvokeAction(String name, Object[] args)
   at Ranorex.Accessible.DoDefaultAction()
   at H_ReportsTest.Program.Main(String[] args) in C:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\H$ReportsTest\H$ReportsTest\Program.cs:line 113

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Fri May 22, 2009 11:31 am

No, you're doing everything right. However, there is a bug in the MSAA plugin causing that calling DoDefaultAction on an element with role Row or Column will always throw a NotSupportedException. We will fix this bug in the next service release.

Until then the only way to invoke DoDefaultAction is the following workaround using reflection:

Code: Select all

Accessible accRow = ...;
Element accRowElement = accRow.Element;
Ranorex.Plugin.MsaaFlavorElement accRowFlavorElement = (Ranorex.Plugin.MsaaFlavorElement)accRowElement.GetType().GetProperty("FlavorElement",
    System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(accRowElement, null);
try
{
    accRowFlavorElement.DoDefaultAction();
}
catch (Exception ex)
{
    throw new ActionFailedException("Invoking action 'DoDefaultAction' failed.", "DoDefaultAction", accRowElement, ex);
}
Regards,
Alex
Ranorex Support Team

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

Post by Ciege » Tue May 26, 2009 6:44 pm

OK, thanks for the update. I will wait for the fix in the service release.