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

[Solved] Text doesn't appear in the Input field

3 Answers 50 Views
Telerik Testing Framework
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
A911
Top achievements
Rank 1
A911 asked on 25 Mar 2010, 02:31 PM
I use a method SendString to put the value in the Input field.
I find the Input field, set the mouse cursor in the field and then call the method SendString, but it's ... empty.

My method is
public void SetValueinFiltertotheField(string text) 
            { 
                HtmlInputText textfield = new HtmlInputText( 
                    _frame.Find.ByParam(SummaryTable.SerializedElements["OperationItems"], TRYCOUNT)); 
                textfield.MouseClick(MouseClickType.LeftClick);; 
                Manager.Current.Desktop.KeyBoard.SendString(text); 
            } 
"OperationItems" element is
  <FindParamItem key="OperationItems"
    <FindParam TagName="input" XPath="" NodeIndexPath="" Type="AttributesOnly" ContentType="TextContent" ContentValue="" TagOccurrenceIndex="-1"
      <Attributes> 
        <iAttribute Name="id" Value="operationItems" /> 
      </Attributes> 
    </FindParam> 
  </FindParamItem> 
SOS! I've no idea why it's not working.



3 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 25 Mar 2010, 03:57 PM
Hello A911,

First, let me ask what would be wrong with simply straight setting the text of your input field? Do you really need to simulate keyboard typing? You can set the text of your input text field directly with code like this:

public void SetValueinFiltertotheField(string text)
{
    HtmlInputText textfield = new HtmlInputText(
        _frame.Find.ByParam(SummaryTable.SerializedElements["OperationItems"], TRYCOUNT));
    textfield.Text = text;
}

The reason your code isn't working as expected is that textfield.MouseClick sends a click event directly to the DOM of the browser. It doesn't change/set the input focus at all. What you need is to do a desktop mouse click instead using code like this:

public void SetValueinFiltertotheField(string text)
{
    HtmlInputText textfield = new HtmlInputText(
        _frame.Find.ByParam(SummaryTable.SerializedElements["OperationItems"], TRYCOUNT));
    //textfield.MouseClick(MouseClickType.LeftClick);
    Manager.Desktop.Mouse.Click(MouseClickType.LeftClick, textfield.GetRectangle());
    Manager.Current.Desktop.KeyBoard.SendString(text);
}

The above code will actually move the mouse cursor to the middle of your input textbox and then simulate a windows mouse click at the current cursor position. That will force input focus to be on input textbox. Then the SendString will work as expected.

All the best,
Cody
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
A911
Top achievements
Rank 1
answered on 01 Apr 2010, 04:05 PM
Thanks a lot for your help. But unfortunately the problem still exists. I used what you advise but it didn't help. We run the tests on virtual machines and I can see how the methods finds the field, the next one sets the cursor here, but the method which simulates keyboard typing doesn't type the digits in the field (FYI: I need to use only the method simulates keyboard typing). I also tried the method KeyPress but I got the same negative result.

I hope you can help me, because I've no idea how to fix this problem :(

I'm looking forward to your reply. Thank you!
0
Cody
Telerik team
answered on 02 Apr 2010, 10:54 PM
Hi Alenka,

Ok, since that didn't work as expected it's time to do some troubleshooting. Questions to answered are:

  • Is the mouse moving and clicking on the right point? You can find out by setting a breakpoint on the SendString line and executing up to this breakpoint. When VS hits the breakpoint, you should be able to see where the mouse cursor is. It should be in the middle of the input box. If it isn't we need to figure out where did it go and why it didn't move to the right location.
  • Does the input box have focus? When VS hits the breakpoint, it may take focus away automatically. Click in the title bar of the IE browser window then type some characters. Do they go into the right input box? If not then the focus didn't get set to the right location.
  • Is SendString working in your VM? You can test this by writing code that launches Notepad and then use the SendString function. If it's working you'll see the characters typed into Notepad.

Let me know what you discover in your debugging and we'll go from there.

Best wishes,
Cody
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Telerik Testing Framework
Asked by
A911
Top achievements
Rank 1
Answers by
Cody
Telerik team
A911
Top achievements
Rank 1
Share this question
or