TestStack | How to find custom controls and invoke methods / fire events












0















I have a custom Control HtButton which inherits from Control.



I made a custom FrameworkElementAutomationPeer and override the OnCreateAutomationPeer() in HtButton.



public class HtButtonAutomationPeer : FrameworkElementAutomationPeer
{
public HtButtonAutomationPeer([NotNull] FrameworkElement owner) : base(owner)
{
}

protected override string GetClassNameCore()
{
return "HtButton";
}
}

public abstract class HtButtonBase : Control
{
}

public class HtButton : HtButtonBase
{
protected override AutomationPeer OnCreateAutomationPeer()
{
return new HtButtonAutomationPeer(this);
}
}


To get all of them, I use the following call:



var myButtons = Window.GetMultiple(SearchCriteria.ByClassName("HtButton"));


I receive a list of CustomUIItem:



enter image description here



The following call throws an ArgumentException: At least two conditions must be specified.:



myButtons = Window.GetMultiple(SearchCriteria.ByControlType(typeof(HtButton), WindowsFramework.Wpf));
foreach (IUIItem myControl in myButtons)
{
if (myControl is HtButton b)
{

}
}


enter image description here



Die Testmethode "HtFramework.WhiteUnitTest.HtPlcFrameworkTest.NavigationTest" hat eine Ausnahme ausgelöst: 
System.ArgumentException: Es müssen mindestens zwei Bedingungen angegeben werden.
bei System.Windows.Automation.OrCondition..ctor(Condition conditions)
bei TestStack.White.UIItems.Finders.OrSearchCondition.get_AutomationCondition() in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsFindersOrSearchCondition.cs:Zeile 27.
bei TestStack.White.UIItems.Finders.SearchCriteria.get_AutomationSearchCondition() in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsFindersSearchCriteria.cs:Zeile 140.
bei TestStack.White.Factory.PrimaryUIItemFactory.CreateAll(SearchCriteria searchCriteria, ActionListener actionListener) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteFactoryPrimaryUIItemFactory.cs:Zeile 80.
bei TestStack.White.UIItems.Container.NonCachedContainerItemFactory.GetAll(SearchCriteria searchCriteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsContainerNonCachedContainerItemFactory.cs:Zeile 30.
bei TestStack.White.UIItems.Container.CurrentContainerItemFactory.FindAll(SearchCriteria criteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsContainerCurrentContainerItemFactory.cs:Zeile 78.
bei TestStack.White.UIItems.UIItemContainer.GetMultiple(SearchCriteria criteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsUIItemContainer.cs:Zeile 205.
bei HtFramework.WhiteUnitTest.MainWindow.NavigateTo() in ...hiddenPath...HtFramework.WhiteUnitTestUnitTest1.cs:Zeile 34.
bei HtFramework.WhiteUnitTest.HtPlcFrameworkTest.<NavigationTest>d__6.MoveNext() in ...hiddenPath...HtFramework.WhiteUnitTestUnitTest1.cs:Zeile 196.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)


I have read the following posts and articles without success






  • TestStack White doesn't find TextBox in WPF Application

  • https://teststackwhite.readthedocs.io/en/latest/AdvancedTopics/CustomUIItems/

  • http://putridparrot.com/blog/teststack-white-gotchatips/


Maybe someone could give me a primitive example how to trigger method Foo() or fire event FooEvent of HtButton.










share|improve this question

























  • A long, long time ago, I wrote this article about looking for controls in a WinRT Store App: pmichaels.net/2013/03/04/… IIRC the premise was based on doing the same in WPF. I don't claim it's an answer to your question, but it might help.

    – Paul Michaels
    Nov 27 '18 at 13:31











  • Did you solve this?

    – Francesco B.
    Nov 30 '18 at 14:33






  • 1





    Actually I switched to FlaUI github.com/Roemer/FlaUI an improoved version of TestStack.White. Your answer did not work like expected. maybe I must have a look at this post.. github.com/TestStack/uia-custom-pattern-managed/blob/master/…

    – Dominic Jonas
    Dec 3 '18 at 9:11











  • Well I changed it after a while :D

    – Francesco B.
    Jan 9 at 7:45
















0















I have a custom Control HtButton which inherits from Control.



I made a custom FrameworkElementAutomationPeer and override the OnCreateAutomationPeer() in HtButton.



public class HtButtonAutomationPeer : FrameworkElementAutomationPeer
{
public HtButtonAutomationPeer([NotNull] FrameworkElement owner) : base(owner)
{
}

protected override string GetClassNameCore()
{
return "HtButton";
}
}

public abstract class HtButtonBase : Control
{
}

public class HtButton : HtButtonBase
{
protected override AutomationPeer OnCreateAutomationPeer()
{
return new HtButtonAutomationPeer(this);
}
}


To get all of them, I use the following call:



var myButtons = Window.GetMultiple(SearchCriteria.ByClassName("HtButton"));


I receive a list of CustomUIItem:



enter image description here



The following call throws an ArgumentException: At least two conditions must be specified.:



myButtons = Window.GetMultiple(SearchCriteria.ByControlType(typeof(HtButton), WindowsFramework.Wpf));
foreach (IUIItem myControl in myButtons)
{
if (myControl is HtButton b)
{

}
}


enter image description here



Die Testmethode "HtFramework.WhiteUnitTest.HtPlcFrameworkTest.NavigationTest" hat eine Ausnahme ausgelöst: 
System.ArgumentException: Es müssen mindestens zwei Bedingungen angegeben werden.
bei System.Windows.Automation.OrCondition..ctor(Condition conditions)
bei TestStack.White.UIItems.Finders.OrSearchCondition.get_AutomationCondition() in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsFindersOrSearchCondition.cs:Zeile 27.
bei TestStack.White.UIItems.Finders.SearchCriteria.get_AutomationSearchCondition() in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsFindersSearchCriteria.cs:Zeile 140.
bei TestStack.White.Factory.PrimaryUIItemFactory.CreateAll(SearchCriteria searchCriteria, ActionListener actionListener) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteFactoryPrimaryUIItemFactory.cs:Zeile 80.
bei TestStack.White.UIItems.Container.NonCachedContainerItemFactory.GetAll(SearchCriteria searchCriteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsContainerNonCachedContainerItemFactory.cs:Zeile 30.
bei TestStack.White.UIItems.Container.CurrentContainerItemFactory.FindAll(SearchCriteria criteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsContainerCurrentContainerItemFactory.cs:Zeile 78.
bei TestStack.White.UIItems.UIItemContainer.GetMultiple(SearchCriteria criteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsUIItemContainer.cs:Zeile 205.
bei HtFramework.WhiteUnitTest.MainWindow.NavigateTo() in ...hiddenPath...HtFramework.WhiteUnitTestUnitTest1.cs:Zeile 34.
bei HtFramework.WhiteUnitTest.HtPlcFrameworkTest.<NavigationTest>d__6.MoveNext() in ...hiddenPath...HtFramework.WhiteUnitTestUnitTest1.cs:Zeile 196.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)


I have read the following posts and articles without success






  • TestStack White doesn't find TextBox in WPF Application

  • https://teststackwhite.readthedocs.io/en/latest/AdvancedTopics/CustomUIItems/

  • http://putridparrot.com/blog/teststack-white-gotchatips/


Maybe someone could give me a primitive example how to trigger method Foo() or fire event FooEvent of HtButton.










share|improve this question

























  • A long, long time ago, I wrote this article about looking for controls in a WinRT Store App: pmichaels.net/2013/03/04/… IIRC the premise was based on doing the same in WPF. I don't claim it's an answer to your question, but it might help.

    – Paul Michaels
    Nov 27 '18 at 13:31











  • Did you solve this?

    – Francesco B.
    Nov 30 '18 at 14:33






  • 1





    Actually I switched to FlaUI github.com/Roemer/FlaUI an improoved version of TestStack.White. Your answer did not work like expected. maybe I must have a look at this post.. github.com/TestStack/uia-custom-pattern-managed/blob/master/…

    – Dominic Jonas
    Dec 3 '18 at 9:11











  • Well I changed it after a while :D

    – Francesco B.
    Jan 9 at 7:45














0












0








0








I have a custom Control HtButton which inherits from Control.



I made a custom FrameworkElementAutomationPeer and override the OnCreateAutomationPeer() in HtButton.



public class HtButtonAutomationPeer : FrameworkElementAutomationPeer
{
public HtButtonAutomationPeer([NotNull] FrameworkElement owner) : base(owner)
{
}

protected override string GetClassNameCore()
{
return "HtButton";
}
}

public abstract class HtButtonBase : Control
{
}

public class HtButton : HtButtonBase
{
protected override AutomationPeer OnCreateAutomationPeer()
{
return new HtButtonAutomationPeer(this);
}
}


To get all of them, I use the following call:



var myButtons = Window.GetMultiple(SearchCriteria.ByClassName("HtButton"));


I receive a list of CustomUIItem:



enter image description here



The following call throws an ArgumentException: At least two conditions must be specified.:



myButtons = Window.GetMultiple(SearchCriteria.ByControlType(typeof(HtButton), WindowsFramework.Wpf));
foreach (IUIItem myControl in myButtons)
{
if (myControl is HtButton b)
{

}
}


enter image description here



Die Testmethode "HtFramework.WhiteUnitTest.HtPlcFrameworkTest.NavigationTest" hat eine Ausnahme ausgelöst: 
System.ArgumentException: Es müssen mindestens zwei Bedingungen angegeben werden.
bei System.Windows.Automation.OrCondition..ctor(Condition conditions)
bei TestStack.White.UIItems.Finders.OrSearchCondition.get_AutomationCondition() in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsFindersOrSearchCondition.cs:Zeile 27.
bei TestStack.White.UIItems.Finders.SearchCriteria.get_AutomationSearchCondition() in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsFindersSearchCriteria.cs:Zeile 140.
bei TestStack.White.Factory.PrimaryUIItemFactory.CreateAll(SearchCriteria searchCriteria, ActionListener actionListener) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteFactoryPrimaryUIItemFactory.cs:Zeile 80.
bei TestStack.White.UIItems.Container.NonCachedContainerItemFactory.GetAll(SearchCriteria searchCriteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsContainerNonCachedContainerItemFactory.cs:Zeile 30.
bei TestStack.White.UIItems.Container.CurrentContainerItemFactory.FindAll(SearchCriteria criteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsContainerCurrentContainerItemFactory.cs:Zeile 78.
bei TestStack.White.UIItems.UIItemContainer.GetMultiple(SearchCriteria criteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsUIItemContainer.cs:Zeile 205.
bei HtFramework.WhiteUnitTest.MainWindow.NavigateTo() in ...hiddenPath...HtFramework.WhiteUnitTestUnitTest1.cs:Zeile 34.
bei HtFramework.WhiteUnitTest.HtPlcFrameworkTest.<NavigationTest>d__6.MoveNext() in ...hiddenPath...HtFramework.WhiteUnitTestUnitTest1.cs:Zeile 196.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)


I have read the following posts and articles without success






  • TestStack White doesn't find TextBox in WPF Application

  • https://teststackwhite.readthedocs.io/en/latest/AdvancedTopics/CustomUIItems/

  • http://putridparrot.com/blog/teststack-white-gotchatips/


Maybe someone could give me a primitive example how to trigger method Foo() or fire event FooEvent of HtButton.










share|improve this question
















I have a custom Control HtButton which inherits from Control.



I made a custom FrameworkElementAutomationPeer and override the OnCreateAutomationPeer() in HtButton.



public class HtButtonAutomationPeer : FrameworkElementAutomationPeer
{
public HtButtonAutomationPeer([NotNull] FrameworkElement owner) : base(owner)
{
}

protected override string GetClassNameCore()
{
return "HtButton";
}
}

public abstract class HtButtonBase : Control
{
}

public class HtButton : HtButtonBase
{
protected override AutomationPeer OnCreateAutomationPeer()
{
return new HtButtonAutomationPeer(this);
}
}


To get all of them, I use the following call:



var myButtons = Window.GetMultiple(SearchCriteria.ByClassName("HtButton"));


I receive a list of CustomUIItem:



enter image description here



The following call throws an ArgumentException: At least two conditions must be specified.:



myButtons = Window.GetMultiple(SearchCriteria.ByControlType(typeof(HtButton), WindowsFramework.Wpf));
foreach (IUIItem myControl in myButtons)
{
if (myControl is HtButton b)
{

}
}


enter image description here



Die Testmethode "HtFramework.WhiteUnitTest.HtPlcFrameworkTest.NavigationTest" hat eine Ausnahme ausgelöst: 
System.ArgumentException: Es müssen mindestens zwei Bedingungen angegeben werden.
bei System.Windows.Automation.OrCondition..ctor(Condition conditions)
bei TestStack.White.UIItems.Finders.OrSearchCondition.get_AutomationCondition() in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsFindersOrSearchCondition.cs:Zeile 27.
bei TestStack.White.UIItems.Finders.SearchCriteria.get_AutomationSearchCondition() in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsFindersSearchCriteria.cs:Zeile 140.
bei TestStack.White.Factory.PrimaryUIItemFactory.CreateAll(SearchCriteria searchCriteria, ActionListener actionListener) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteFactoryPrimaryUIItemFactory.cs:Zeile 80.
bei TestStack.White.UIItems.Container.NonCachedContainerItemFactory.GetAll(SearchCriteria searchCriteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsContainerNonCachedContainerItemFactory.cs:Zeile 30.
bei TestStack.White.UIItems.Container.CurrentContainerItemFactory.FindAll(SearchCriteria criteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsContainerCurrentContainerItemFactory.cs:Zeile 78.
bei TestStack.White.UIItems.UIItemContainer.GetMultiple(SearchCriteria criteria) in c:TeamCitybuildAgentwork89a20b30302799esrcTestStack.WhiteUIItemsUIItemContainer.cs:Zeile 205.
bei HtFramework.WhiteUnitTest.MainWindow.NavigateTo() in ...hiddenPath...HtFramework.WhiteUnitTestUnitTest1.cs:Zeile 34.
bei HtFramework.WhiteUnitTest.HtPlcFrameworkTest.<NavigationTest>d__6.MoveNext() in ...hiddenPath...HtFramework.WhiteUnitTestUnitTest1.cs:Zeile 196.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)


I have read the following posts and articles without success






  • TestStack White doesn't find TextBox in WPF Application

  • https://teststackwhite.readthedocs.io/en/latest/AdvancedTopics/CustomUIItems/

  • http://putridparrot.com/blog/teststack-white-gotchatips/


Maybe someone could give me a primitive example how to trigger method Foo() or fire event FooEvent of HtButton.







c# wpf automated-tests white teststack






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 14:35







Dominic Jonas

















asked Nov 27 '18 at 13:16









Dominic JonasDominic Jonas

1,5691528




1,5691528













  • A long, long time ago, I wrote this article about looking for controls in a WinRT Store App: pmichaels.net/2013/03/04/… IIRC the premise was based on doing the same in WPF. I don't claim it's an answer to your question, but it might help.

    – Paul Michaels
    Nov 27 '18 at 13:31











  • Did you solve this?

    – Francesco B.
    Nov 30 '18 at 14:33






  • 1





    Actually I switched to FlaUI github.com/Roemer/FlaUI an improoved version of TestStack.White. Your answer did not work like expected. maybe I must have a look at this post.. github.com/TestStack/uia-custom-pattern-managed/blob/master/…

    – Dominic Jonas
    Dec 3 '18 at 9:11











  • Well I changed it after a while :D

    – Francesco B.
    Jan 9 at 7:45



















  • A long, long time ago, I wrote this article about looking for controls in a WinRT Store App: pmichaels.net/2013/03/04/… IIRC the premise was based on doing the same in WPF. I don't claim it's an answer to your question, but it might help.

    – Paul Michaels
    Nov 27 '18 at 13:31











  • Did you solve this?

    – Francesco B.
    Nov 30 '18 at 14:33






  • 1





    Actually I switched to FlaUI github.com/Roemer/FlaUI an improoved version of TestStack.White. Your answer did not work like expected. maybe I must have a look at this post.. github.com/TestStack/uia-custom-pattern-managed/blob/master/…

    – Dominic Jonas
    Dec 3 '18 at 9:11











  • Well I changed it after a while :D

    – Francesco B.
    Jan 9 at 7:45

















A long, long time ago, I wrote this article about looking for controls in a WinRT Store App: pmichaels.net/2013/03/04/… IIRC the premise was based on doing the same in WPF. I don't claim it's an answer to your question, but it might help.

– Paul Michaels
Nov 27 '18 at 13:31





A long, long time ago, I wrote this article about looking for controls in a WinRT Store App: pmichaels.net/2013/03/04/… IIRC the premise was based on doing the same in WPF. I don't claim it's an answer to your question, but it might help.

– Paul Michaels
Nov 27 '18 at 13:31













Did you solve this?

– Francesco B.
Nov 30 '18 at 14:33





Did you solve this?

– Francesco B.
Nov 30 '18 at 14:33




1




1





Actually I switched to FlaUI github.com/Roemer/FlaUI an improoved version of TestStack.White. Your answer did not work like expected. maybe I must have a look at this post.. github.com/TestStack/uia-custom-pattern-managed/blob/master/…

– Dominic Jonas
Dec 3 '18 at 9:11





Actually I switched to FlaUI github.com/Roemer/FlaUI an improoved version of TestStack.White. Your answer did not work like expected. maybe I must have a look at this post.. github.com/TestStack/uia-custom-pattern-managed/blob/master/…

– Dominic Jonas
Dec 3 '18 at 9:11













Well I changed it after a while :D

– Francesco B.
Jan 9 at 7:45





Well I changed it after a while :D

– Francesco B.
Jan 9 at 7:45












1 Answer
1






active

oldest

votes


















-1














There are other solutions I guess, some of which are a bit involved in my opionion (i.e. creating a custom UIItem subclass and so on).



What I finally went for is this:



var myButtons = Window.GetMultiple(SearchCriteria.ByClassName("HtButton"));
foreach (var button in myButtons )
{
dynamic t = button;
t.Foo();
}


It does definitely work, it's short and just requires you to reference Microsoft.CSharp.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53500604%2fteststack-how-to-find-custom-controls-and-invoke-methods-fire-events%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    -1














    There are other solutions I guess, some of which are a bit involved in my opionion (i.e. creating a custom UIItem subclass and so on).



    What I finally went for is this:



    var myButtons = Window.GetMultiple(SearchCriteria.ByClassName("HtButton"));
    foreach (var button in myButtons )
    {
    dynamic t = button;
    t.Foo();
    }


    It does definitely work, it's short and just requires you to reference Microsoft.CSharp.






    share|improve this answer




























      -1














      There are other solutions I guess, some of which are a bit involved in my opionion (i.e. creating a custom UIItem subclass and so on).



      What I finally went for is this:



      var myButtons = Window.GetMultiple(SearchCriteria.ByClassName("HtButton"));
      foreach (var button in myButtons )
      {
      dynamic t = button;
      t.Foo();
      }


      It does definitely work, it's short and just requires you to reference Microsoft.CSharp.






      share|improve this answer


























        -1












        -1








        -1







        There are other solutions I guess, some of which are a bit involved in my opionion (i.e. creating a custom UIItem subclass and so on).



        What I finally went for is this:



        var myButtons = Window.GetMultiple(SearchCriteria.ByClassName("HtButton"));
        foreach (var button in myButtons )
        {
        dynamic t = button;
        t.Foo();
        }


        It does definitely work, it's short and just requires you to reference Microsoft.CSharp.






        share|improve this answer













        There are other solutions I guess, some of which are a bit involved in my opionion (i.e. creating a custom UIItem subclass and so on).



        What I finally went for is this:



        var myButtons = Window.GetMultiple(SearchCriteria.ByClassName("HtButton"));
        foreach (var button in myButtons )
        {
        dynamic t = button;
        t.Foo();
        }


        It does definitely work, it's short and just requires you to reference Microsoft.CSharp.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 '18 at 19:24









        Francesco B.Francesco B.

        1,64631324




        1,64631324
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53500604%2fteststack-how-to-find-custom-controls-and-invoke-methods-fire-events%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)