如何使用编码的ui从网页获取文本

时间:2014-05-13 12:45:07

标签: selenium-webdriver coded-ui-tests microsoft-test-manager visual-studio-test-runner

I am new for coded ui and I have got stuck for processing message display on webpage. As we used to get text from web page in selenium using method getText(), is such kind of possibility are available in coded ui.?

I would appreciate your help!!!!

Thanks,
Dani

更新 - 2014年5月14日

脚本代码:

 public void FPInternetExplorer()
        {
            #region Variable Declarations
            HtmlEdit uIUserNameEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIUserNameEdit;
            HtmlEdit uIPasswordEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIPasswordEdit;
            HtmlInputButton uILoginButton = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UILoginButton;
            HtmlEdit uISecurityQuestionAnswEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UISecurityQuestionAnswEdit;
            HtmlInputButton uIValidateButton = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIValidateButton;
            #endregion

            this.UIInternetExplorerEnhaWindow6.LaunchUrl(new System.Uri(this.FPInternetExplorerParams.UIInternetExplorerEnhaWindow6Url));

            // Type 'test@test.test' in 'User Name' text box
            uIUserNameEdit.Text = this.FPInternetExplorerParams.UIUserNameEditText;

            // Type '{Tab}' in 'User Name' text box
            Keyboard.SendKeys(uIUserNameEdit, this.FPInternetExplorerParams.UIUserNameEditSendKeys, ModifierKeys.None);

            // Type '********' in 'Password' text box
            uIPasswordEdit.Password = this.FPInternetExplorerParams.UIPasswordEditPassword;

            // Click 'Login' button
            Mouse.Click(uILoginButton, new Point(62, 19));

    //Code to get the text from div tag. This is the code I have added  
            HtmlDiv testLabel = new HtmlDiv();
            testLabel.SearchProperties[HtmlDiv.PropertyNames.Id] = "SecurityQuestion_AnswerText";
            string myText = testLabel.InnerText;
            Console.Write("myText " + myText);

            // Type 'Computer' in 'SecurityQuestion.AnswerText' text box
            uISecurityQuestionAnswEdit.Text = this.FPInternetExplorerParams.UISecurityQuestionAnswEditText;

            // Type '{Tab}' in 'SecurityQuestion.AnswerText' text box
            Keyboard.SendKeys(uISecurityQuestionAnswEdit, this.FPInternetExplorerParams.UISecurityQuestionAnswEditSendKeys, ModifierKeys.None);

            // Click 'Validate' button
            Mouse.Click(uIValidateButton, new Point(81, 25));
        }

//使用编码的UI运行此代码时,系统会给出异常:消息 - '要测试Windows应用商店应用,请在Windows应用商店节点下使用Windows应用商店应用的编码用户界面测试项目模板。'这段代码中缺少什么?如果您能提供配置缺失组件的链接

,将不胜感激

1 个答案:

答案 0 :(得分:0)

您正在寻找的属性是" InnerText"。因此,例如,在如下的超链接上:

HtmlHyperlink target = new HtmlHyperlink();
target.SearchProperties[<search property>] = <value>;
string myText = target.InnerText;

您可以通过选择页面的外部容器并获取其内部文本来读取页面上的所有文本,然后通过字符串解析您想要的内容,但我已经找到了它如果你在最集中的对象中工作,那就简单多了。