【问题标题】:AutomationElement ScrollBar throws Access Violation on ScrollVerticalAutomationElement ScrollBar 在 ScrollVertical 上引发访问冲突
【发布时间】:2014-10-04 06:15:10
【问题描述】:

我正在尝试使用以下代码在第三方 .net 应用程序中滚动滚动条。当我在 Visual Studio 中运行代码时,它会引发访问冲突。当我在 Visual Studio 之外执行程序集时,它显示 Unsupported Pattern.... 任何想法都非常感谢 =]

if(child.Current.ClassName == "ScrollBar")
{
    PropertyCondition condition = new PropertyCondition(AutomationElement.AutomationIdProperty, child.Current.AutomationId);
    AutomationElement btnElement = child.FindFirst(TreeScope.Element, condition);
    ScrollPattern btnPattern = btnElement.GetCurrentPattern(ScrollPattern.Pattern) as ScrollPattern;
    btnPattern.ScrollVertical(ScrollAmount.LargeIncrement);
}

【问题讨论】:

    标签: c# ui-automation microsoft-ui-automation


    【解决方案1】:

    我会做的检查很少:

    1. 您的 btnElement 缺少空值检查。
    2. 确保滚动条确实存在(滚动模式不会暴露,除非窗格大小超过窗口大小 - 如果这样设计的话)。
    3. 最后,不要直接将模式作为 ScrollPattern 获取,而是尝试从 bthElement 获取 GetAllSupportedPatterns,确保 Scroll Pattern 确实存在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      • 1970-01-01
      • 2017-01-17
      • 2018-02-28
      • 1970-01-01
      相关资源
      最近更新 更多