小编sae*_*eed的帖子

UI 自动化 - 为另一个应用程序的文本框设置文本

我有两种形式。当单击其中一个按钮时,我想打开另一个按钮并在其中填充一个文本框。我尝试使用下面的代码,但它给出了一个错误,指出“不支持的模式”。

这是我的代码:

private void button1_Click(object sender, EventArgs e)
{
    string automationId = "Form1";
    string newTextBoxValue = "user1";
    var condition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationId);
    var textBox = AutomationElement.RootElement.FindFirst(TreeScope.Subtree, condition);
    ValuePattern vPattern = (ValuePattern)textBox.GetCurrentPattern(ValuePattern.Pattern);
    vPattern.SetValue(newTextBoxValue);
}
Run Code Online (Sandbox Code Playgroud)

.net c# ui-automation winforms

3
推荐指数
1
解决办法
3346
查看次数

标签 统计

.net ×1

c# ×1

ui-automation ×1

winforms ×1