【问题标题】:Need to enter Text需要输入文字
【发布时间】:2019-05-17 18:56:27
【问题描述】:

我尝试使用 Get 查找元素,但它不起作用,这就是我使用 GetElement 方法的原因

我正在尝试在使用 C# 在 teststack white 中使用 GetElement 找到的文本框元素中输入文本

我想知道如何将自动化元素转换为 UIitem,以便我可以对该元素执行 enter() 或单击操作

var all = appWindow.GetElement(SearchCriteria.ByControlType(ControlType.ComboBox)
    .AndByText("Model collapsed"));
var element = all.FindFirst(TreeScope.Children, 
    new PropertyCondition(AutomationElement.NameProperty, "Edit Box collapsed"));
element.enter("");

当我执行 element.enter 或单击它时会出错,我想我需要强制转换它,或者有其他方法可以实现这一点。谢谢。

【问题讨论】:

  • 任何人都有解决方案
  • var all = appWindow.GetElement(SearchCriteria.ByControlType(ControlType.ComboBox).AndByText("模型折叠")); var element = all.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "编辑框折叠"));文本框 textBox = new TextBox(element, appWindow.ActionListener); textBox.SetValue(textValue);我现在可以找到文本框,但我得到{“无法执行操作。”}。我试过 .enter("") 但没有运气同样的错误..

标签: c# white-framework teststack


【解决方案1】:

使用下面的代码后,我可以输入文字了。

var all = appWindow.GetElement(SearchCriteria.ByControlType(ControlType.ComboBox)
.AndByText(parentValue));
 var element = all.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, childValue));
                TextBox textBox = new TextBox(all, appWindow.ActionListener);

 TestStack.White.InputDevices.AttachedKeyboard keyboard = appWindow.Keyboard;
                textBox .Click();
                keyboard.Enter("test");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-17
    相关资源
    最近更新 更多