This is a migrated thread and some comments may be shown as answers.

How to get the text in textbox?

4 Answers 156 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
lucia
Top achievements
Rank 1
lucia asked on 12 Jan 2012, 07:01 AM
HI everyone,
I tried to get the text in textbox, but I am failed!
My scenario is like this:
When the web page is opened, some data will be retrived from DB and fill in the textbox, now I'd like to verify the text in the textbox, but can not get it. Below is my test code

silApp.RefreshVisualTrees();
string sex=silApp.FindName("patientinfo").Find.ByName("tbSex").TextBlockContent);

After executed the code,  the string sex is still empty, but actually it's not and should be "F". Further more I can see the text on webpage, just can not get from the test code.
           

4 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 12 Jan 2012, 10:15 PM
Hello Lucia,

If you're certain you're finding the TextBox element correctly, then simply change .TextBlockContent to .Text.

Since you're verifying an editable TextBox, then there is no TextBlock, so .TextBlockContent doesn't apply.

All the best,
Anthony
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
lucia
Top achievements
Rank 1
answered on 13 Jan 2012, 01:44 AM
Hi Anthony ,
I am sure the textbox does exist, and I can see it on the web page.
I have ever tried . .TextBlockContent /.Text/.literalText, but all are empty,,none can get the text of the textbox.
Any other resolution?
Thanks!!!                 
0
Anthony
Telerik team
answered on 13 Jan 2012, 06:50 PM
Hello Lucia,

I'm sure the TextBox is present on the page, what I meant was are you sure the Find Expression is targeting to correct element?

See below for an example against a public site. The Find Expression is rather complex. If the TextBox in your case has a unique name, then you can more easily identify it.

Manager.Settings.Web.EnableSilverlight = true;
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo("http://demos.telerik.com/silverlight/#DataForm/FirstLook");
 
SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
 
TextBox tb = app.Find.ByExpression(new XamlFindExpression("XamlTag=autogeneratedfieldspresenter", "name=PART_AutoGeneratedFieldsPresenter", "|", "XamlPath=/itemscontrol[0]/itemspresenter[0]/virtualizingstackpanel[0]", "|", "VirtualizedIndex=0", "|", "XamlPath=/border[name=PART_RootElement]/grid[name=PART_DataFormDataFieldGrid]/contentpresenter[name=PART_ContentPresenter]/textbox[0]")).As<TextBox>();
 
Log.WriteLine(tb.Text);

Kind regards,
Anthony
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
lucia
Top achievements
Rank 1
answered on 17 Jan 2012, 01:57 AM
HI Anthony,
That's great!! The issue is resolved following your sample. thanks again for your help!!

lucia
Tags
General Discussions
Asked by
lucia
Top achievements
Rank 1
Answers by
Anthony
Telerik team
lucia
Top achievements
Rank 1
Share this question
or