问题
Getting HP.LFT.SDK.GeneralReplayException: One or more specified arguments are not valid, while trying to click on a wpf button (using LeanFT with C# integrated in Visual Studio 2015 )
Given the code below:
// Identify the "LicensingButton" button
var LicensingButton = objAdminApplicationModel.wnd_Adminstration.Describe<IButton>(new ButtonDescription
{
Text = @"Licensing",
ObjectName = @"Licensing"
});
// Click the Licensing button.
LicensingButton.Click();
But I am getting below exception
Exception is HP.LFT.SDK.GeneralReplayException: One or more specified arguments are not valid.
at HP.LFT.SDK.Core.ClassModel.TestObjectExecuterBase.HandleReplayError(Int32 errorCode, IDictionary`2 data)
at HP.LFT.SDK.Core.Communication.CommunicationClient.HandleError(Action`2 onError, Int32 status, IDictionary`2 data)
at HP.LFT.SDK.Core.Communication.CommunicationClient.Send(String messageType, IDictionary`2 data, Action`2 onError)
at HP.LFT.SDK.Core.ClassModel.TestObjectExecuter.ExecuteMethod(String methodName, Object[] arguments)
at HP.LFT.SDK.Core.ClassModel.TestObjectBase.ExecuteMethod(String methodName, Object[] arguments)
at HP.LFT.SDK.ClickBehaviour.Click(MouseButton button)
at HP.LFT.SDK.UiObjectBase.<>c__DisplayClassd.<Click>b__c()
at HP.LFT.SDK.OperationExecutionWrapper.ExecuteWithEvents(ITestObject testObject, Object additionalInfo, Action innerAction, MethodBase methodInfo, Boolean reportOnlyOnError, Object[] arguments)
at HP.LFT.SDK.OperationExecutionWrapper.ExecuteWithEvents[T1](Action innerAction, Action`1 originalMethod, T1 param1, Boolean reportOnlyOnError, ITestObject testObject, Object additionalInfo)
at HP.LFT.SDK.UiObjectBase.Click(MouseButton button)
at Admin4DM.Test.Licensing.Licensing_VerifyStaticTextDisplay() in C:\Source\Automation\Test\Licensing.cs:line 32
回答1:
The exception is indeed misleading. On a first look I thought the ButtonDescription is incorrectly constructed, meaning that one of Text or ObjectName property expects some other value.
But that's not the case.
The problem lies entirely in the click operation. As you can see when inspecting the Click method, it has two overloads:
Expecting a
MouseButtonenum;When we call
Clickand we don't pass the enum or the object,MouseButton.Leftenum value is used by default but you can also specify.Middleor.Right.Expecting a
ClickArgsobject, in the form of:new ClickArgs { Button = MouseButton.Left, Location = Position.Center }Locationindicates where to click the button. (.BottomLeft,.BottomRight,.Center,.TopLeftand.TopRight).Actually if we use the
MouseButtonoverload, it still uses thePositionbut clicks onPosition.Centerby default.
Now that the theory is over (phew), let's see what happens in practice.
The exception we see shows us that something obviously went wrong when clicking on that button, more specifically an exception was thrown while attempting to click on Position.Center with the MouseButton.Left. As .Center is calculated based on button's width and height property, probably there is some issue with the button that causes wrong calculations (unfortunatelly I can only assume this, I can't tell you for sure).
By the way, if this happens on any button of the AUT you're testing, most probably the devs are doing something wrong, as it's not common (for example, on the WPF I'm testing, I don't have the issue on any of the buttons).
What we can do is to attempt the followings:
- Try clicking with
.Middleor.Right; - Try clicking in other positions of the button using the
Positionenum; Try clicking in other positions of the button using
HP.SDK.LFT.Mouse;// Use Mouse class to click on the button in a fine tuned location var loc = LicensingButton.AbsoluteLocation; var p = new System.Drawing.Point(loc.X + 5, loc.Y + 5); Mouse.Click(p, MouseButton.Left);Try identifying the object as Insight image-based identification;
- Try identifying the object using VRI;
- Try identifying some parent object (if possible) and execute the
Clickoperation in such a way that it "hits" the button you want to actually click
来源:https://stackoverflow.com/questions/48269906/leanft-c-sharp-automation-clicking-on-a-wpf-button-control-throwing-exception