How to use SendKeys method of WinAppDriverUIRecorder.RecordedUiTask class

Best WinAppDriver code snippet using WinAppDriverUIRecorder.RecordedUiTask.SendKeys

RecordedUiTask.cs

Source:RecordedUiTask.cs Github

copy

Full Screen

...207 sb.AppendLine(GenerateCSCode.Wheel(this, VariableName));208 }209 else if (this.UiTaskName == EnumUiTaskName.KeyboardInput)210 {211 sb.AppendLine(GenerateCSCode.SendKeys(this, focusedElemName));212 }213 return sb.ToString();214 }215 public void ChangeClickToDoubleClick()216 {217 this.UiTaskName = EnumUiTaskName.LeftDblClick;218 this._strDescription = null;219 }220 public void DragComplete(int deltaX, int deltaY)221 {222 this.DeltaX = deltaX;223 this.DeltaY = deltaY;224 this.UiTaskName = EnumUiTaskName.Drag;225 this._strDescription = null;226 }227 public void UpdateWheelData(int delta)228 {229 this.DeltaX += 1;230 this.DeltaY += delta;231 this._strDescription = null;232 }233 }234 class GenerateCSCode235 {236 public static string GetCodeBlock(RecordedUiTask uiTask, string elemName, string uiActionLine)237 {238 var xpath = "xpath_" + elemName;239 elemName = "winElem_" + elemName;240 string codeBlock = $"string {xpath} = {uiTask.GetXPath(true)};\n" +241 $"var {elemName} = desktopSession.FindElementByAbsoluteXPath({xpath});\n" +242 $"if ({elemName} != null)\n" +243 "{\n" +244 "CODEBLOCK" +245 "}\n" +246 "else\n" +247 "{\n" +248 " Console.WriteLine($\"Failed to find element using xpath: {" + $"{xpath}" + "}\");\n" +249 " return;\n" +250 "}\n";251 return codeBlock.Replace("CODEBLOCK", uiActionLine);252 }253 public static string LeftClick(RecordedUiTask uiTask, string elemName)254 {255 string codeLine = $" winElem_{elemName}.Click();\n";256 return GetCodeBlock(uiTask, elemName, codeLine);257 }258 public static string DoubleClick(RecordedUiTask uiTask, string elemName)259 {260 string codeLine = $" desktopSession.DesktopSessionElement.Mouse.MouseMove(winElem_{elemName}.Coordinates);\n" +261 $" desktopSession.DesktopSessionElement.Mouse.DoubleClick(null);\n";262 return GetCodeBlock(uiTask, elemName, codeLine);263 }264 public static string RightClick(RecordedUiTask uiTask, string elemName)265 {266 string codeLine = $" desktopSession.DesktopSessionElement.Mouse.MouseMove(winElem_{elemName}.Coordinates);\n" +267 $" desktopSession.DesktopSessionElement.Mouse.ContextClick(null);\n";268 return GetCodeBlock(uiTask, elemName, codeLine);269 }270 public static string Wheel(RecordedUiTask uiTask, string elemName)271 {272 string codeLine = $" //TODO: Wheel at ({uiTask.Left},{uiTask.Top}) on winElem_{elemName}, Count:{uiTask.DeltaX}, Total Amount:{uiTask.DeltaY}\n";273 return GetCodeBlock(uiTask, elemName, codeLine);274 }275 public static List<string> GetDecodedKeyboardInput(string strBase64, bool bCapsLock, bool bNumLock, bool bScrollLock)276 {277 byte[] data = Convert.FromBase64String(strBase64);278 int i = 0;279 bool shift = false;280 StringBuilder sb = new StringBuilder();281 List<string> lines = new List<string>();282 int nCtrlKeyDown = 0;283 while (i < data.Length / 2)284 {285 int n1 = i * 2;286 int n2 = i * 2 + 1;287 i++;288 bool bIsKeyDown = data[n1] == 0;289 VirtualKeys vk = (VirtualKeys)data[n2];290 char ch = ConstVariables.Vk2char((int)vk, shift || bCapsLock);291 if (bIsKeyDown) //Keydown292 {293 if (char.IsControl(ch))294 {295 nCtrlKeyDown++;296 if (nCtrlKeyDown == 1 && sb.Length > 0)297 {298 lines.Add("\"" + sb.ToString() + "\"");299 sb.Clear();300 }301 string vkStr = vk.ToString();302 string vkSendKey = ConstVariables.Vk2string(vkStr);303 if (nCtrlKeyDown == 1)304 sb.Append("Keys." + vkSendKey);305 else306 sb.Append(" + Keys." + vkSendKey);307 }308 else if (ch != 0)309 {310 string strToAppend = ch.ToString();311 if (ch == '\\')312 {313 strToAppend += "\\";314 }315 if (nCtrlKeyDown > 0)316 {317 sb.Append(" + \"" + strToAppend + "\"");318 }319 else320 {321 sb.Append(strToAppend);322 }323 }324 }325 else //Keyup326 {327 if (char.IsControl(ch))328 {329 nCtrlKeyDown--;330 string vkStr = vk.ToString();331 string vkSendKey = ConstVariables.Vk2string(vkStr);332 if (nCtrlKeyDown == 0)333 {334 lines.Add(sb.ToString() + " + Keys." + vkSendKey);335 sb.Clear();336 }337 else338 {339 sb.Append(" + Keys." + vkSendKey);340 }341 }342 }343 }344 if (sb.Length > 0)345 {346 lines.Add("\"" + sb.ToString() + "\"");347 }348 return lines;349 }350 public static string SendKeys(RecordedUiTask uiTask, string focusedElemeName)351 {352 List<string> lines = GetDecodedKeyboardInput(uiTask.Base64Text, uiTask.CapsLock, uiTask.NumLock, uiTask.ScrollLock);353 StringBuilder sb = new StringBuilder();354 focusedElemeName = "winElem_" + focusedElemeName;355 sb.AppendLine($"System.Threading.Thread.Sleep(100);");356 foreach (string line in lines)357 {358 sb.AppendLine($"{focusedElemeName}.SendKeys({line});");359 }360 return sb.ToString();361 }362 }363}...

Full Screen

Full Screen

SendKeys

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Text;4using System.Windows.Forms;5using WinAppDriverUIRecorder;6{7 {8 public RecordedUiTask()9 {10 }11 public void SendKeys(string keys)12 {13 SendKeys.SendWait(keys);14 }15 }16}17using System;18using System.Collections.Generic;19using System.Text;20using System.Windows.Forms;21using WinAppDriverUIRecorder;22{23 {24 public RecordedUiTask()25 {26 }27 public void SendKeys(string keys)28 {29 SendKeys.SendWait(keys);30 }31 }32}33using System;34using System.Collections.Generic;35using System.Text;36using System.Windows.Forms;37using WinAppDriverUIRecorder;38{39 {40 public RecordedUiTask()41 {42 }43 public void SendKeys(string keys)44 {45 SendKeys.SendWait(keys);46 }47 }48}49using System;50using System.Collections.Generic;51using System.Text;52using System.Windows.Forms;53using WinAppDriverUIRecorder;54{55 {56 public RecordedUiTask()57 {58 }59 public void SendKeys(string keys)60 {61 SendKeys.SendWait(keys);62 }63 }64}65using System;66using System.Collections.Generic;67using System.Text;68using System.Windows.Forms;69using WinAppDriverUIRecorder;70{71 {72 public RecordedUiTask()73 {74 }75 public void SendKeys(string keys)76 {77 SendKeys.SendWait(keys);78 }79 }80}81using System;

Full Screen

Full Screen

SendKeys

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestTools.UnitTesting;7using OpenQA.Selenium;8using OpenQA.Selenium.Appium.Windows;9using OpenQA.Selenium.Remote;10using WinAppDriverUIRecorder;11{12 {13 public static WindowsDriver<WindowsElement> session;14 public static WinAppDriverUIRecorder.RecordedUiTask recordedUiTask;15 public static void ClassInitialize(TestContext context)16 {17 DesiredCapabilities appCapabilities = new DesiredCapabilities();18 appCapabilities.SetCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");

Full Screen

Full Screen

SendKeys

Using AI Code Generation

copy

Full Screen

1{2 {3 static void Main(string[] args)4 {5 RecordedUiTask recordedUiTask = new RecordedUiTask();6 recordedUiTask.SendKeys("Hello World!");7 }8 }9}10{11 {12 static void Main(string[] args)13 {14 RecordedUiTask recordedUiTask = new RecordedUiTask();15 recordedUiTask.SendKeys("Hello World!");16 }17 }18}19{20 {21 static void Main(string[] args)22 {23 RecordedUiTask recordedUiTask = new RecordedUiTask();24 recordedUiTask.SendKeys("Hello World!");25 }26 }27}28{29 {30 static void Main(string[] args)31 {32 RecordedUiTask recordedUiTask = new RecordedUiTask();33 recordedUiTask.SendKeys("Hello World!");34 }35 }36}

Full Screen

Full Screen

SendKeys

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading;3using WinAppDriverUIRecorder;4{5 {6 static void Main(string[] args)7 {8 RecordedUiTask task = new RecordedUiTask();9 Thread thread = new Thread(task.Run);10 thread.Start();11 Thread.Sleep(5000);12 task.SendKeys("Hello World!");13 Thread.Sleep(5000);14 task.Stop();15 }16 }17}18using System;19using System.Threading;20using WinAppDriverUIRecorder;21{22 {23 static void Main(string[] args)24 {25 RecordedUiTask task = new RecordedUiTask();26 Thread thread = new Thread(task.Run);27 thread.Start();28 Thread.Sleep(5000);29 task.Click();30 Thread.Sleep(5000);31 task.Stop();32 }33 }34}35using System;36using System.Threading;37using WinAppDriverUIRecorder;38{39 {40 static void Main(string[] args)41 {42 RecordedUiTask task = new RecordedUiTask();43 Thread thread = new Thread(task.Run);

Full Screen

Full Screen

SendKeys

Using AI Code Generation

copy

Full Screen

1using OpenQA.Selenium.Appium.Windows;2using System;3using System.Threading;4using WinAppDriverUIRecorder;5using System.Windows.Forms;6{7 {8 static void Main(string[] args)9 {10 WindowsDriver<WindowsElement> session = null;11 {12 if (session == null)13 {14 DesiredCapabilities appCapabilities = new DesiredCapabilities();15 appCapabilities.SetCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run WinAppDriver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful