This is a migrated thread and some comments may be shown as answers.

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

1 Answer 102 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chunks
Top achievements
Rank 1
Chunks asked on 14 Nov 2012, 01:39 AM
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

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 16 Nov 2012, 09:24 AM
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
Tags
General Discussions
Asked by
Chunks
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or