0

I have an issue with setting value of AutomationElement by using method ValuePattern.SetValue().

Everything works just fine until some dialog appears. When the dialog appears the code execution got stuck. No exception is thrown. After the dialog is confirmed, the code exection continues. Bellow is a sample of the code:

            BasePattern basePattern = null;
            ValuePattern valuePattern = null;

            AutomationElement elementA = Window.GetElement(SearchCriteria.ByText(propertyName));

            object patternObjectA = null;          
            elementA.TryGetCurrentPattern(ValuePattern.Pattern, out patternObjectA);               

            basePattern = (BasePattern)patternObjectA;
            valuePattern = (ValuePattern)patternObjectA;     

            valuePattern.SetValue(optionToSet);

// Window.GetElement() is a method from TestStack.White framework

// The code execution got stuck on the last line until the dialog is confirmed

Is there any other way to set AutomationElement value?

Is somehow possible to avoid of getting stuck by dialog?

I'll by grateful for any help. Thanks advance.

1 Answers1

1

It could be that this dialog is not supporting UI Automation correctly or that you simply target the wrong element.

To verify that you may use Inspect.exe from Microsoft or similiar tools.inspect.exe example


If it works, check if you really target the correct component with your code again.

If it does not work and:

  • if you are able to change the application

    1. you can change the so called AutomationPeer of the UI component - here is a link for more infos
    2. Or simply use another UI component that supports UI Automation correctly.
  • if you are not able to change the application, and also do not need to run in background, parallel, etc.. you might just focus the component (call setFocus() onto the AutomationElement, or expand it (via IsExpandCollapsePatternAvailable or simulated MouseClick onto the components coordinates)) and then use the SendKeys.SendWait("test") method.


EDIT: There is one more thing you should have a look at, and I wonder why I didn't mentioned it in the first place: Register to UI Automation Events For example you could register a callback for the Structure change event type, and check if the dialog you talk about appeared. If so --> click the confirmed button of the dialog.

Probably you will have to synchronize your execution, so that every further action in the UI Automation script waits until the registered callback got executed and the confirmed button got clicked.

Haphil
  • 1,180
  • 1
  • 14
  • 33
  • 1
    I've been working on other issue so I've almost forgot about this one. I've done what you adviced and use Value.SetValue function in Inspect, but I encountered a similar issue. When the dialog appears then Inspect got stuck. After the dialog is confirmed then Inspect starts working. What do you mean by Use another element that supports UI Automation correctly? Also SendKeys.SendWait() won't be the solution, because the UI Element I try to automate is option list (list view drop down), you need to choose an option not enter a value. – Olafvolafka Oct 31 '19 at 09:21
  • Because Inspect.exe has the same issue with that "list view drop down" I strongly believe that UI Automation API of the "list view drop down" is broken. Therefore the issue lies in your application under test (and not the UI Automation code you wrote). With "Use another element" I mean to choose a different UI component (other than "list view drop down") that implements the UI Automation API correctly. If you need to use this "list view drop down" for some reason you could "change the AutomationPeer" as also suggested... – Haphil Nov 05 '19 at 09:47
  • And regarding SendKeys.SendWait(): I think to recall that standard drop down menus use to work with it, but you might have to expand them first (using the IsExpandCollapsePatternAvailable - if IsExpandCollapsePatternAvailable is not supported (which would be again an issue of the UI component regarding UI Automation) you could try to use a (automated) MouseClick onto the components coordinates instead...) – Haphil Nov 05 '19 at 09:56
  • I thank you for all of your well comprehensive answers. For now, I'm going to process it. Hope I'll finally solve this problem. – Olafvolafka Nov 06 '19 at 08:13
  • @Olafvolafka just noticed there is another option for you, please read the added 'EDIT'-section. – Haphil Nov 15 '19 at 12:09