0
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

updated - 5/14/2014

script code:

 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));
        }

// When run this code using coded UI, system gives exception: Message - 'To test Windows Store apps, use the Coded UI Test project template for Windows Store apps under the Windows Store node.' Is something missing in this code? Would appreciate if you could provide link to configure missing component

Karim Narsindani
  • 434
  • 3
  • 14
  • 38
  • Use the cross-hairs tool to record an assertion on the text you want. From the assertion method in the `uimap.designer.cs` file copy the code that gathers the text and put it into your own code. Delete the call to the assertion method. – AdrianHHH May 13 '14 at 13:41
  • @AdrianHHH thanks for your comment, I will look into uimap.designer.cs as suggested by you. – Karim Narsindani May 14 '14 at 05:02

1 Answers1

0

The property you're looking for is "InnerText". So, for example, on a hyperlink like:

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

You can extrapolate this to just read all of the text on the page by selecting the outer container of the page and getting the InnerText of it, then parse through the string for what you want, but I've found it a lot simpler if you work in the most focused object.

Ryan Cox
  • 938
  • 1
  • 7
  • 22
  • I really appreciate your inputs. I will use the sample code given by and let you know if I face any problem Thanks Dani – Karim Narsindani May 14 '14 at 05:04
  • Hi Rayan, I have added below code in my script ' HtmlDiv testLabel = new HtmlDiv(); testLabel.SearchProperties[HtmlDiv.PropertyNames.Id] = "SecurityQuestion_AnswerText"; // testLabel.SearchProperties[HtmlDiv.PropertyNames.Name] = "SecurityQuestion.AnswerText"; string myText = testLabel.InnerText; Console.Write("myText " + myText); and system display exception To test Windows Store apps, use the Coded UI Test project template for Windows Store apps under the Windows Store node. Is something missing? Can you pls help? Thanks – Karim Narsindani May 14 '14 at 07:01
  • @dani It may be better to edit the question to show the code you have added. That way it can be formatted to be readable. If the code is generating an exception then show the actual message, not a summary of it. Otherwise explain in detail what is or is not happening. – AdrianHHH May 14 '14 at 07:46
  • Thanks, Ryan & Adrian. Now I am able to get the text from web page, I have recorded an assertion and copied the code from method and stored in string variable. HtmlDiv uQuestion = this.UIInternetExplorerEnhaWindow.UIFundingPilotPortalDocument.UIWhatisyourfavouritepPane; string getQuestion = uQuestion.InnerText; It worked for me thanks, – Karim Narsindani May 14 '14 at 11:26