Solving "Exception has been thrown by the target of an invocation"

2 posts, 0 answers
  1. Chunks
    Chunks avatar
    17 posts
    Member since:
    Nov 2011

    Posted 13 Nov 2012 Link to this post

    Hello All,

    I trying to use this code in one my tests, but the second function use to cast the element into Tcontrol is throwing this exception -- Exception has been thrown by the target of an invocation . Any idea what am I doing wrong here?

    ===
    var Element = Manager.Current.ActiveBrowser.WaitForElement(Config.Timeout,
                                                                                                  "id=test");
    return Element .As<T>();
    ===

    Thanks,
    Aakash
  2. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 16 Nov 2012 Link to this post

    Hello Aakash,

    It is hard to determine what is causing the problem without seeing the full exception and the complete code you are using. Are you trying to use a Generic method? If so, I have tested the following code against the Google starting page and it works as expected.
    public T WaitForElement<T>() where T : ArtOfTest.WebAii.Controls.HtmlControls.HtmlControl, new()
    {
     
        var Element = Manager.Current.ActiveBrowser.WaitForElement(10000, "id=gbqfba");
        return Element.As<T>();
     
    }

    [CodedStep(@"New Coded Step")]
    public void WebTest1_CodedStep()
    {           
        HtmlButton button = WaitForElement<HtmlButton>();
        button.Click(false);
    }

    Please provide more detailed information on the issue you are experiencing, so we can continue troubleshooting.

    Regards,
    Plamen
    the Telerik team
    Are you enjoying Test Studio? We’d appreciate your vote in the ATI automation awards.
    Vote now
Back to Top