【问题标题】:UI Automation: How to change value of a horizontal scrollbar AutomationElementUI 自动化:如何更改水平滚动条 AutomationElement 的值
【发布时间】:2012-06-16 04:16:42
【问题描述】:

我正在尝试将水平滚动条的值从 -1 更改为 -2。 我可以访问它.. 但接下来我必须更改它的值..

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

_clickButtonElement 是滚动条父窗口的AutomationElement。

【问题讨论】:

    标签: c# visual-studio-2010 user-interface automation scrollbar


    【解决方案1】:

    滚动条通常支持RangeValuePattern。使用类似的东西:

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

    请注意,无论内部值如何,滚动条通常都会标准化为 0..100。因此,如果滚动条内部使用值 -5 到 5,则滚动条的中间点 0 实际上会通过 RangeValuePattern 暴露为 50。

    您可能希望使用Inspect tool 来确保您获得正确的元素,并且它也支持这种模式。您还可以在编写任何代码之前使用 Inspect 通过其 UI 调用 RangeValue.SetValue()。

    【讨论】:

    • 感谢您的帮助。它仍然给出了一个例外作为“不支持的模式”。在调试模式下,“Current”属性中的“LocalizedControlType”属性显示为“窗格”。 “名称”属性被指定为“水平滚动条”。在 spy++ 中观察到的该元素的“类”是我在上面使用的“WindowsForms10.SCROLLBAR.app.0.378734a”。这是我能找到的信息..
    • 您可能想探索树,看看附近是否有真正的滚动条控件;也许作为一个孩子或作为你的兄弟姐妹。有时控件有额外的窗格作为父或祖先来管理布局。很好奇,这是什么应用 - 是知名应用,还是您自己的代码或一些内部应用?
    • 这是窗口中唯一的滚动条类型元素。该应用程序是由公司的一些人开发的。没有可用的源代码。它是一个 Windows 应用程序。我所指的元素是树中的叶节点。树中没有其他类似的元素。它是应用程序窗口的子项。我确定我可以正确访问它(通过上面提到的 classNameProperty 。)。但不知道改变它的价值。感谢您有兴趣提供帮助。
    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-05
      • 2012-09-16
      • 1970-01-01
      相关资源
      最近更新 更多