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

How to send keys in elemnt.

21 Answers 1120 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Anton asked on 08 Aug 2012, 01:17 PM

Hi.

How can i send keys in element?

for example: i need to press 'Enter' key in text field.

ActiveBrowser.Desktop...SendString type text in address bar of IE.

21 Answers, 1 is accepted

Sort by
0
Jonas
Top achievements
Rank 2
answered on 09 Aug 2012, 05:05 AM
Hello Anton,

There is some ways this can be made.

Sample code (C#):
var myApplication = ActiveBrowser.Desktop;
var textBox = myApplication.MyTextBox;
 
MyTextBox.User.KeyPress(Key.Enter, 5);
 
// Summary:
//     Press a key and hold it down for a specific period of time.
//
// Parameters:
//   key:
//     The key code for the key to press.
//
//   holdFor:
//     How long to hold the key down, in milliseconds.
public void KeyPress(Keys key, int holdFor)
0
Anton
Top achievements
Rank 1
answered on 09 Aug 2012, 07:26 AM

Hello.

I don't understand what is 'MyTextBox' in 

var textBox = myApplication.MyTextBox;
Maybe this is for Silverlight application?

I need to send keys for HTML Controls.

0
Cody
Telerik team
answered on 10 Aug 2012, 10:26 PM
Hello Anton,

Jonas's code sample is for a Silverlight application. I'm going to assume you're dealing with an HTML based application. In this realm the framework doesn't really understand the concept of "Press Enter on an element". Instead we need to do two steps:
1) Click on the element to give it input focus
2) Simulate pressing the Enter key on the keyboard

Here's some sample C# code to do this:

HtmlInputText input = ActiveBrowser.Find.ById<HtmlInputText>("inputid");
Manager.Desktop.Mouse.Click(MouseClickType.LeftClick, input.GetRectangle());
Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Enter);

To get the VB equivalent just use our code converter.

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Anton
Top achievements
Rank 1
answered on 14 Aug 2012, 02:14 PM

Thanks, it's works for me:

Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Enter, 100);
0
Anton
Top achievements
Rank 1
answered on 14 Aug 2012, 02:23 PM
oh...no... sorry, but it's works only sometimes.
0
Anton
Top achievements
Rank 1
answered on 14 Aug 2012, 02:27 PM

oh...

It works for me

.Manager.Desktop.KeyBoard.KeyPress(Keys.Enter, 100, 3);

0
Cody
Telerik team
answered on 14 Aug 2012, 03:04 PM
Hi Anton,

I am glad to hear you found a solution! Thank you for the update.

All the best,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Ashna
Top achievements
Rank 1
answered on 20 Mar 2013, 11:08 AM
Hi,
   Can u please tell how to get this Manager.Desktop.Keyboard reference?? I can't find any dll file for it nor when i type this code in silverlight project, it gives any sort of reference to it. Actually i need to send F11 key on button click in silverlight... Is there any way to do so?
0
Plamen
Telerik team
answered on 25 Mar 2013, 03:14 PM
Hello Ashna,

You can use the Manager.Desktop.Keyboard class only in a test project. The Manager object cannot be used in your Silverlight project. See the bottom of this page for more information on the Manager object.

Maybe you can accomplish your goal using the SendKeys Class.

Regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Ashna
Top achievements
Rank 1
answered on 26 Mar 2013, 10:35 AM
No... This SendKeys class is present in System.Windows.Forms dll. and i don't think it willl work in silverlight.
Is there any other way to send keys in silverlight...??
0
Plamen
Telerik team
answered on 26 Mar 2013, 11:21 AM
Hello Ashna,

I am sorry but that is beyond the scope of Test Studio support. This forum is dedicated to supporting our Telerik Testing Framework product. That's really a question for the Microsoft Silverlight team since you're dealing with a Silverlight app and thus unrelated to Telerik Testing Framework.

Regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Chris
Top achievements
Rank 1
answered on 08 Jan 2014, 06:21 PM
Hi Cody,

I have tried exactly the code you described to Anton with regard to the HTML application as I have the same need. I am able to set the input on the correct field via the mouse click, however the Keypress does not appear to do anything. When I try to run my test in debug mode, no error is thrown by the Keypress line.. Nothing seems to happen at all.

Any assistance on this would be greatly appreciated.
0
Boyan Boev
Telerik team
answered on 13 Jan 2014, 12:30 PM
Hello Chris,

I am sorry you are running into this problem.

What code exactly do you use? What do you want to type in the field?

Please double check that the focus is on the particular input.

You can also use this code:

Manager.Desktop.KeyBoard.SendString("asdfasdf");

Let me know if this helps.

Regards,
Boyan Boev
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Chris
Top achievements
Rank 1
answered on 13 Jan 2014, 02:51 PM
I have tried a couple of different ways of doing this. Shown below is my current approach. Nothing seems to happen using the Keypress method. Interestingly, I can set any field I need to if I use .Text, .InnherHtml, .InnerText, etc directly. However, for this case I specifically need to test a user submitting a form via the Enter key rather than using a click event on the submit button.

<Test, TestCase(Titan.AdminUser, Titan.AdminPW, Titan.AdminUserDesc)>
    Public Sub LoginSuccessViaEnter(userName As String, password As String, fullName As String)
      ' Navigate directly to the login page
      Titan.TitanManager.ActiveBrowser.NavigateTo(Pages.ClientLogin.Path)
      Titan.TitanManager.ActiveBrowser.WaitUntilReady()
 
      Dim userNameField As HtmlInputText = Titan.TitanManager.ActiveBrowser.Find.ByName(Of HtmlInputText)("ctl00$ContentPlaceHolder1$txtUserId")
      Dim passWordField As HtmlInputPassword = Titan.TitanManager.ActiveBrowser.Find.ByName(Of HtmlInputPassword)("ctl00$ContentPlaceHolder1$txtPassword")
 
      userNameField.Text = userName
      passWordField.Text = password
 
      ' TODO: FIX THIS TO TRIGGER AN ENTER KEYPRESS
      Titan.TitanManager.Desktop.Mouse.Click(MouseClickType.LeftClick, userNameField.GetRectangle())     
      Titan.TitanManager.ActiveBrowser.Manager.Desktop.KeyBoard.KeyPress(Windows.Forms.Keys.Enter)
      Titan.TitanManager.ActiveBrowser.WaitUntilReady()
 
      Titan.CheckCurrentUrl(Pages.Home.Path)
 
      Dim loginHeaderText As String = Titan.TitanManager.ActiveBrowser.Find.ById(Of HtmlAnchor)("ctl00_hypAUser").InnerText
      StringAssert.AreEqualIgnoringCase(loginHeaderText, fullName)
    End Sub

I have also tried this instead of the Keypress method and it also appears to do nothing.

Titan.TitanManager.Desktop.KeyBoard.SendString("test")

0
Chris
Top achievements
Rank 1
answered on 13 Jan 2014, 11:23 PM
I changed my code to the line below and it appears to work now:

Titan.TitanManager.ActiveBrowser.Desktop.KeyBoard.KeyPress(ArtOfTest.WebAii.Win32.KeyBoard.KeysFromString("Enter"), 150, 1)

However, I have a new issue. After the enter keypress, the ActiveBrowser.Url does not appear to change (the login triggers a redirect - in the version of this test where I login in via a button click instead of pressing enter, ActiveBrowser.Url does change as expected).

At first I thought that the code was simply moving on too quickly so I tried WaitUntilReady() to no success. Eventually I tried simply sleeping the thread for a few seconds as sort of a brute-force solution but even after sleeping it and where I could see the correct page was loaded in the browser, ActiveBrowser.Url had not changed.

Any ideas?
0
Chunks
Top achievements
Rank 1
answered on 14 Jan 2014, 10:46 PM
Hey Chris, Have you tried refreshing the dom tree(...ActiveBrowser.RefershDomTree() )? before asserting the current url.
0
Boyan Boev
Telerik team
answered on 16 Jan 2014, 10:29 AM
Hello Chris,

This is very strange issue that we have never seen. 

What is happening if you refresh the page (i.e. ActiveBrowser.Refresh();)?

Another thing you can try is to replace sending key Enter with a click step with SimulateRealClick property set to true (i.e. yourElement.MouseClick(MouseClickType.LeftClick);).

Hope this helps.

Regards,
Boyan Boev
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Satheesh
Top achievements
Rank 1
answered on 17 Jul 2017, 02:03 PM
For Windows Phone application, How can I send username and password values ...can I have sample code for it....simple login access...am very new face for CodedUI testing...
0
Nikolay Petrov
Telerik team
answered on 20 Jul 2017, 10:09 AM
Hi Satheesh,

Unfortunately Windows Phone is not supported for automation at this point of product development. In this article and related links you could fine all information related to the mobile automation aspect as a feature set in Test Studio.

Kind Regards,
Nikolay Petrov
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Pankaj
Top achievements
Rank 1
answered on 16 Jul 2018, 01:26 PM

Hi Guys, 

I was trying to perform some Keyboard operations (Key Press and Tab etc) in sample CRM application provided by Telerik using telerik test studio v 2018.2. 

I have recorded the case and when i am compiling the coded file its giving me below error :

D:\Users\patiwari\Documents\Test Studio Projects\PracticeTelerik\WPFTest.tstest.vb(62,0) : error BC30451: 'Keys' is not declared. It may be inaccessible due to its protection level.
D:\Users\patiwari\Documents\Test Studio Projects\PracticeTelerik\WPFTest.tstest.vb(65,0) : error BC30451: 'Key' is not declared. It may be inaccessible due to its protection level.

 

Also attaching the screenshot of my code file

 

Can anyone help me into this how i can resolve this issue. 

Many Thanks in Advance..

 

 

 

 

 

 

 

 

 

 

 

0
Elena
Telerik team
answered on 17 Jul 2018, 03:09 PM
Hi Pankaj,

Thank you for your interest in Test Studio. 

If you are about to use the Desktop Manager you will need to add reference in the Test Studio project to System.Windows.Forms.dll as described in the first note in this article

I hope this will be helpful to you. Thank you! 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Anton
Top achievements
Rank 1
Answers by
Jonas
Top achievements
Rank 2
Anton
Top achievements
Rank 1
Cody
Telerik team
Ashna
Top achievements
Rank 1
Plamen
Telerik team
Chris
Top achievements
Rank 1
Boyan Boev
Telerik team
Chunks
Top achievements
Rank 1
Satheesh
Top achievements
Rank 1
Nikolay Petrov
Telerik team
Pankaj
Top achievements
Rank 1
Elena
Telerik team
Share this question
or