UIAutomation Throwing exception message : Operation is not valid due to the current state of the object.

Liu Hao 20 Reputation points
2024-08-30T03:36:28.63+00:00

code:User's image

tabElement is a control that requires operation and has not been disabled.

exception message : **System.InvalidOperationException:**Operation is not valid due to the current state of the object.

Why did this abnormal message appear.

supplement:User's imageException only occurs when the remote window is minimized.

When the remote window is minimized, is sendInput invalid for the remote window.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,737 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 32,376 Reputation points Microsoft Vendor
    2024-08-30T07:32:31.0833333+00:00

    Hi @Liu Hao ,

    Ensure that tabElement actually supports the SelectionItemPattern.

    If tabElement.TryGetCurrentPattern(SelectionItemPattern.Pattern, selectInvoke) Then
        selectInvoke.Select()
    Else
        ' Handle the case where the pattern is not supported
    End If
    
    

    Try verifying that the tabElement is ready by checking properties like tabElement.Current.IsEnabled and tabElement.Current.IsOffscreen.

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.