UI Automation: How to change value of a horizontal scrollbar AutomationElement

强颜欢笑 提交于 2020-01-05 03:52:07

问题


I am trying to change the value of a horizontal scrollbar from -1 to -2. I am able to get access to it.. but next i have to change its value..

AutomationElement _sideBar = _ClickButtonElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "WindowsForms10.SCROLLBAR.app.0.378734a"));

_clickButtonElement is the AutomationElement of the parent window of the scrollbar.


回答1:


Scrollbars usually support RangeValuePattern. Use something like:

RangeValuePattern range = scrollbar.GetCurrentPattern(RangeValuePattern.Pattern) as RangeValuePattern;
range.SetValue(50); // Set to half way point

Note that usually scrollbars are normalized to 0..100, regardless of internal values. So if a scrollbar internally uses values -5 to 5, then the scrollbar's half-way point of 0 will actually be exposed via RangeValuePattern as 50.

You might want to use the Inspect tool to ensure that you are getting the correct element, and that it also supports this pattern. You can also use Inspect to call RangeValue.SetValue() through its UI before you write any code.




回答2:


AutomationElement aeForm = AutomationElement.FromHandle(windowPtr);

AutomationElementCollection buttonCollection = aeForm.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ScrollBar));          

AutomationElement aeButton = buttonCollection[1];

RangeValuePattern rcpattern = (RangeValuePattern)aeButton.GetCurrentPattern(RangeValuePattern.Pattern);
rcpattern.SetValue(50.00);


来源:https://stackoverflow.com/questions/11010940/ui-automation-how-to-change-value-of-a-horizontal-scrollbar-automationelement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!