How to I inject programmatic text into my Coded UI

2019-02-26 22:36发布

The recorder works fine for quickly getting some steps thrown down, but I need to be able to store and set arbitrary text. Let's say I generated a new admin user called Admin001. I want to be able to set the text for the control to be "Admin001", not whatever was recorded when I first used the builder.

I know you can do data bindings to CSV and the like, but that's too burdensome. I want to be able to write C# code to change which text is typed.

Screenshot:

enter image description here

Code attempt:

            var loginElement = new UILoginInternetExploreWindow().UILoginDocument.UIUserNameorEmailAddreEdit.Text;

So I'm able to get the property .Text (I think), but not actually set it...

1条回答
smile是对你的礼貌
2楼-- · 2019-02-26 23:02

to set the property just do:

new UILoginInternetExploreWindow().UILoginDocument.UIUserNameorEmailAddreEdit.Text = 
"Some Text";

or:

var loginControl = new UILoginInternetExploreWindow().UILoginDocument.UIUserNameorEmailAddreEdit;
loginControl.Text = "Some Text";
查看更多
登录 后发表回答