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

Finding HtmlInputText using text next to it.

1 Answer 45 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
SD
Top achievements
Rank 1
SD asked on 06 Sep 2011, 06:36 AM
Hi guys, 

Sometimes it's easier to find (And then write into) an input text field by the text description next to it. 
I've been using xpath for that ever since but tried to find a more elegant approach..
The following is a pretty common design..
<table>
<tbody>
<tr>
<td>Reason waived</td>
<td>
<input id="feeForm:reasonWaived" type="text" name="feeForm:reasonWaived"/>
</td>
<td/>
</tr>
</tbody>
</table>
Tried this. The first element in the array is without a doubt the input element. The thing is, I was not able to use that element in a SetText method for instance...Any ideas ? 
    Element txtNextTohtmlInputText = Manager.ActiveBrowser.Find.ByContent("Reason Waived");
    Element htmlInputTextParent = txtNextTohtmlInputText.GetNextSibling();
    htmlInputTextParent.GetChildren().First();//The InputText field.

1 Answer, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 07 Sep 2011, 10:37 PM
Hi Sd,

Why not find the input element by its ID and set the text directly into that element?

HtmlInputText input = Find.ByExpression<HtmlInputText>("id=feeForm:reasonWaived");
input.Text = "New Text";


All the best,
Anthony
the Telerik team
Vote for Telerik Test Studio at the Annual Automation Honors Voting!
Tags
General Discussions
Asked by
SD
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Share this question
or