Best WinAppDriver code snippet using WinAppDriverUIRecorder.CharPair.CharPair
GenerateXPath.cs
Source:GenerateXPath.cs
...29 MouseWheel,30 MouseHover,31 Inspect32 }33 public class CharPair34 {35 public CharPair(char c1, char c2)36 {37 char1 = c1;38 char2 = c2;39 }40 public char char1;41 public char char2;42 }43 class ConstVariables44 {45 public static Dictionary<string, string> s_Vk2String = new Dictionary<string, string>();46 public static Dictionary<int, CharPair> s_Vk2CharPair = new Dictionary<int, CharPair>();47 public static EnumUiTaskName FromStringTaskName(string strTask)48 {49 foreach (EnumUiTaskName val in Enum.GetValues(typeof(EnumUiTaskName)))50 {51 if (strTask == val.ToString())52 {53 return val;54 }55 }56 return EnumUiTaskName.UnknownUiTask;57 }58 public static void InitVk2StringMap()59 {60 s_Vk2String.Add(VirtualKeys.VK_NUMPAD0.ToString(), "NumberPad0");61 s_Vk2String.Add(VirtualKeys.VK_NUMPAD1.ToString(), "NumberPad1");62 s_Vk2String.Add(VirtualKeys.VK_NUMPAD2.ToString(), "NumberPad2");63 s_Vk2String.Add(VirtualKeys.VK_NUMPAD3.ToString(), "NumberPad3");64 s_Vk2String.Add(VirtualKeys.VK_NUMPAD4.ToString(), "NumberPad4");65 s_Vk2String.Add(VirtualKeys.VK_NUMPAD5.ToString(), "NumberPad5");66 s_Vk2String.Add(VirtualKeys.VK_NUMPAD6.ToString(), "NumberPad6");67 s_Vk2String.Add(VirtualKeys.VK_NUMPAD7.ToString(), "NumberPad7");68 s_Vk2String.Add(VirtualKeys.VK_NUMPAD8.ToString(), "NumberPad8");69 s_Vk2String.Add(VirtualKeys.VK_NUMPAD9.ToString(), "NumberPad9");70 s_Vk2String.Add(VirtualKeys.VK_MULTIPLY.ToString(), "Multiply");71 s_Vk2String.Add(VirtualKeys.VK_ADD.ToString(), "Add");72 s_Vk2String.Add(VirtualKeys.VK_SEPARATOR.ToString(), "Separator");73 s_Vk2String.Add(VirtualKeys.VK_OEM_NEC_EQUAL.ToString(), "Equal");74 s_Vk2String.Add(VirtualKeys.VK_SUBTRACT.ToString(), "Subtract");75 s_Vk2String.Add(VirtualKeys.VK_DIVIDE.ToString(), "Divide");76 s_Vk2String.Add(VirtualKeys.VK_F1.ToString(), "F1");77 s_Vk2String.Add(VirtualKeys.VK_F2.ToString(), "F2");78 s_Vk2String.Add(VirtualKeys.VK_F3.ToString(), "F3");79 s_Vk2String.Add(VirtualKeys.VK_F4.ToString(), "F4");80 s_Vk2String.Add(VirtualKeys.VK_F5.ToString(), "F5");81 s_Vk2String.Add(VirtualKeys.VK_F6.ToString(), "F6");82 s_Vk2String.Add(VirtualKeys.VK_F7.ToString(), "F7");83 s_Vk2String.Add(VirtualKeys.VK_F8.ToString(), "F8");84 s_Vk2String.Add(VirtualKeys.VK_F9.ToString(), "F9");85 s_Vk2String.Add(VirtualKeys.VK_F10.ToString(), "F10");86 s_Vk2String.Add(VirtualKeys.VK_F11.ToString(), "F11");87 s_Vk2String.Add(VirtualKeys.VK_F12.ToString(), "F12");88 s_Vk2String.Add(VirtualKeys.VK_DECIMAL.ToString(), "Decimal");89 s_Vk2String.Add(VirtualKeys.VK_OEM_1.ToString(), "Semicolon");90 s_Vk2String.Add(VirtualKeys.VK_INSERT.ToString(), "Insert");91 s_Vk2String.Add(VirtualKeys.VK_CANCEL.ToString(), "Cancel");92 s_Vk2String.Add(VirtualKeys.VK_HELP.ToString(), "Help");93 s_Vk2String.Add(VirtualKeys.VK_BACK.ToString(), "Backspace");94 s_Vk2String.Add(VirtualKeys.VK_TAB.ToString(), "Tab");95 s_Vk2String.Add(VirtualKeys.VK_CLEAR.ToString(), "Clear");96 s_Vk2String.Add(VirtualKeys.VK_RETURN.ToString(), "Return");97 s_Vk2String.Add(VirtualKeys.VK_LSHIFT.ToString(), "LeftShift");98 s_Vk2String.Add(VirtualKeys.VK_RSHIFT.ToString(), "Shift");99 s_Vk2String.Add(VirtualKeys.VK_LCONTROL.ToString(), "LeftControl");100 s_Vk2String.Add(VirtualKeys.VK_RCONTROL.ToString(), "Control");101 s_Vk2String.Add(VirtualKeys.VK_LMENU.ToString(), "LeftAlt");102 s_Vk2String.Add(VirtualKeys.VK_RMENU.ToString(), "Alt");103 s_Vk2String.Add(VirtualKeys.VK_DELETE.ToString(), "Delete");104 s_Vk2String.Add(VirtualKeys.VK_PAUSE.ToString(), "Pause");105 s_Vk2String.Add(VirtualKeys.VK_SPACE.ToString(), "Space");106 s_Vk2String.Add(VirtualKeys.VK_PRIOR.ToString(), "PageUp");107 s_Vk2String.Add(VirtualKeys.VK_NEXT.ToString(), "PageDown");108 s_Vk2String.Add(VirtualKeys.VK_END.ToString(), "End");109 s_Vk2String.Add(VirtualKeys.VK_HOME.ToString(), "Home");110 s_Vk2String.Add(VirtualKeys.VK_LEFT.ToString(), "ArrowLeft");111 s_Vk2String.Add(VirtualKeys.VK_UP.ToString(), "ArrowUp");112 s_Vk2String.Add(VirtualKeys.VK_RIGHT.ToString(), "ArrowRight");113 s_Vk2String.Add(VirtualKeys.VK_DOWN.ToString(), "ArrowDown");114 s_Vk2String.Add(VirtualKeys.VK_ESCAPE.ToString(), "Escape");115 s_Vk2String.Add(VirtualKeys.VK_LWIN.ToString(), "Command");116 s_Vk2String.Add(VirtualKeys.VK_RWIN.ToString(), "Command");117 s_Vk2CharPair.Add(0x30, new CharPair('0', ')'));118 s_Vk2CharPair.Add(0x31, new CharPair('1', '!'));119 s_Vk2CharPair.Add(0x32, new CharPair('2', '@'));120 s_Vk2CharPair.Add(0x33, new CharPair('3', '#'));121 s_Vk2CharPair.Add(0x34, new CharPair('4', '$'));122 s_Vk2CharPair.Add(0x35, new CharPair('5', '%'));123 s_Vk2CharPair.Add(0x36, new CharPair('6', '^'));124 s_Vk2CharPair.Add(0x37, new CharPair('7', '&'));125 s_Vk2CharPair.Add(0x38, new CharPair('8', '*'));126 s_Vk2CharPair.Add(0x39, new CharPair('9', '('));127 s_Vk2CharPair.Add((int)VirtualKeys.VK_OEM_3, new CharPair('`', '~'));128 s_Vk2CharPair.Add((int)VirtualKeys.VK_OEM_MINUS, new CharPair('-', '_'));129 s_Vk2CharPair.Add((int)VirtualKeys.VK_OEM_PLUS, new CharPair('=', '+'));130 s_Vk2CharPair.Add((int)VirtualKeys.VK_OEM_4, new CharPair('[', '{'));131 s_Vk2CharPair.Add((int)VirtualKeys.VK_OEM_6, new CharPair(']', '}'));132 s_Vk2CharPair.Add((int)VirtualKeys.VK_OEM_5, new CharPair('\\', '|'));133 s_Vk2CharPair.Add((int)VirtualKeys.VK_OEM_1, new CharPair(';', ':'));134 s_Vk2CharPair.Add((int)VirtualKeys.VK_OEM_7, new CharPair(',', '<'));135 s_Vk2CharPair.Add((int)VirtualKeys.VK_OEM_PERIOD, new CharPair('.', '>'));136 s_Vk2CharPair.Add((int)VirtualKeys.VK_OEM_2, new CharPair('/', '?'));137 s_Vk2CharPair.Add(0x41, new CharPair('a', 'A'));138 s_Vk2CharPair.Add(0x42, new CharPair('b', 'B'));139 s_Vk2CharPair.Add(0x43, new CharPair('c', 'C'));140 s_Vk2CharPair.Add(0x44, new CharPair('d', 'D'));141 s_Vk2CharPair.Add(0x45, new CharPair('e', 'E'));142 s_Vk2CharPair.Add(0x46, new CharPair('f', 'F'));143 s_Vk2CharPair.Add(0x47, new CharPair('g', 'G'));144 s_Vk2CharPair.Add(0x48, new CharPair('h', 'H'));145 s_Vk2CharPair.Add(0x49, new CharPair('i', 'I'));146 s_Vk2CharPair.Add(0x4A, new CharPair('j', 'J'));147 s_Vk2CharPair.Add(0x4B, new CharPair('k', 'K'));148 s_Vk2CharPair.Add(0x4C, new CharPair('l', 'L'));149 s_Vk2CharPair.Add(0x4D, new CharPair('m', 'M'));150 s_Vk2CharPair.Add(0x4E, new CharPair('n', 'N'));151 s_Vk2CharPair.Add(0x4F, new CharPair('o', 'O'));152 s_Vk2CharPair.Add(0x50, new CharPair('p', 'P'));153 s_Vk2CharPair.Add(0x51, new CharPair('q', 'Q'));154 s_Vk2CharPair.Add(0x52, new CharPair('r', 'R'));155 s_Vk2CharPair.Add(0x53, new CharPair('s', 'S'));156 s_Vk2CharPair.Add(0x54, new CharPair('t', 'T'));157 s_Vk2CharPair.Add(0x55, new CharPair('u', 'U'));158 s_Vk2CharPair.Add(0x56, new CharPair('v', 'V'));159 s_Vk2CharPair.Add(0x57, new CharPair('w', 'W'));160 s_Vk2CharPair.Add(0x58, new CharPair('x', 'X'));161 s_Vk2CharPair.Add(0x59, new CharPair('y', 'Y'));162 s_Vk2CharPair.Add(0x5A, new CharPair('z', 'Z'));163 }164 public static string Vk2string(string vkString)165 {166 if (s_Vk2String.ContainsKey(vkString))167 {168 return s_Vk2String[vkString];169 }170 else171 {172 return vkString;173 }174 }175 public static char Vk2char(int vk, bool bShiftDown)176 {177 if (s_Vk2CharPair.ContainsKey(vk))178 {179 CharPair chaiPaire = s_Vk2CharPair[vk];180 return bShiftDown ? chaiPaire.char2 : chaiPaire.char1;181 }182 return (char)0;183 }184 }185 class GenerateXPath186 {187 const string sNameValue = "[@{0}=\\\"{1}\\\"]";188 const string sNameStartsWithValue = "[starts-with(@{0},\\\"{1}\\\")]";189 public static string XmlEncode(string strData)190 {191 if (strData != null)192 {193 strData = strData.Replace("&", "&");...
CharPair
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using WinAppDriverUIRecorder;7using System.Windows.Automation;8using System.Windows.Forms;9{10 {11 static void Main(string[] args)12 {13 IntPtr handle = WinAppDriverUIRecorder.CharPair.GetWindowHandle("Calculator");14 AutomationElement element = AutomationElement.FromHandle(handle);15 AutomationElement edit = element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "CalculatorResults"));16 Console.WriteLine(edit.GetCurrentPropertyValue(AutomationElement.NameProperty));17 edit.SetFocus();18 SendKeys.SendWait("10+20");19 SendKeys.SendWait("{ENTER}");20 Console.WriteLine(edit.GetCurrentPropertyValue(AutomationElement.NameProperty));21 Console.ReadLine();22 }23 }24}
CharPair
Using AI Code Generation
1using System;2using System.Windows.Forms;3using System.Drawing;4using System.Drawing.Imaging;5using System.IO;6using System.Diagnostics;7using System.Threading;8using System.Runtime.InteropServices;9using System.Collections.Generic;10using System.Linq;11{12 {13 public Form1()14 {15 InitializeComponent();16 }17 private void Form1_Load(object sender, EventArgs e)18 {19 this.Size = Screen.PrimaryScreen.Bounds.Size;20 Label label = new Label();21 label.Text = "Hello World";22 label.AutoSize = true;23 label.Location = new Point(10, 10);24 this.Controls.Add(label);25 }26 private void Form1_FormClosing(object sender, FormClosingEventArgs e)27 {28 Bitmap bitmap = new Bitmap(this.Width, this.Height);29 this.DrawToBitmap(bitmap, new Rectangle(0, 0, this.Width, this.Height));30 bitmap.Save("screenshot.png", ImageFormat.Png);31 }32 private void button1_Click(object sender, EventArgs e)33 {34 ProcessStartInfo start = new ProcessStartInfo();35 start.FileName = "python.exe";36 start.Arguments = "C:\\Users\\user\\Documents\\Visual Studio 2015\\Projects\\WinAppDriverUIRecorder\\WinAppDriverUIRecorder\\4.py";37 start.UseShellExecute = false;38 start.RedirectStandardOutput = true;39 start.CreateNoWindow = true;40 Process p = Process.Start(start);41 p.WaitForExit();42 string output = p.StandardOutput.ReadToEnd();43 p.Close();44 MessageBox.Show(output);45 }46 }47}48import sys49import os50import time51import win32gui52import win32ui53import win32con54import win32api55hWnd = win32gui.FindWindow(None, 'Form1')56hWndDC = win32gui.GetWindowDC(hWnd)57mfcDC = win32ui.CreateDCFromHandle(hWndDC)58saveDC = mfcDC.CreateCompatibleDC()59saveBitMap = win32ui.CreateBitmap()60saveBitMap.CreateCompatibleBitmap(mfcDC, 300,
CharPair
Using AI Code Generation
1using System;2using System.Windows.Forms;3{4 {5 public Form1()6 {7 InitializeComponent();8 }9 private void button1_Click(object sender, EventArgs e)10 {11 CharPair myPair = new CharPair();12 myPair.FirstChar = 'A';13 myPair.SecondChar = 'B';14 textBox1.Text = myPair.ToString();15 }16 }17}
CharPair
Using AI Code Generation
1string text = "Hello world";2string pair = CharPair(text, 5);3string text = "Hello world";4string pair = CharPair(text, 5);5string text = "Hello world";6string pair = CharPair(text, 5);7string text = "Hello world";8string pair = CharPair(text, 5);9string text = "Hello world";10string pair = CharPair(text, 5);11string text = "Hello world";12string pair = CharPair(text, 5);13string text = "Hello world";14string pair = CharPair(text, 5);15string text = "Hello world";16string pair = CharPair(text, 5);
CharPair
Using AI Code Generation
1string c = "a";2string d = WinAppDriverUIRecorder.CharPair(c);3string e = c + d;4string f = e + c;5string g = f + d;6string h = g + c;7string i = h + d;8string j = i + c;9string k = j + d;10string l = k + c;11string m = l + d;12string n = m + c;13string o = n + d;14string p = o + c;15string q = p + d;16string r = q + c;17string s = r + d;18string t = s + c;19string u = t + d;20string v = u + c;21string w = v + d;22string x = w + c;23string y = x + d;24string z = y + c;25string aa = z + d;26string ab = aa + c;27string ac = ab + d;28string ad = ac + c;29string ae = ad + d;30string af = ae + c;31string ag = af + d;32string ah = ag + c;33string ai = ah + d;34string aj = ai + c;35string ak = aj + d;36string al = ak + c;37string am = al + d;38string an = am + c;39string ao = an + d;40string ap = ao + c;41string aq = ap + d;42string ar = aq + c;43string as = ar + d;44string at = as + c;45string au = at + d;46string av = au + c;47string aw = av + d;48string ax = aw + c;49string ay = ax + d;50string az = ay + c;51string ba = az + d;52string bb = ba + c;53string bc = bb + d;54string bd = bc + c;55string be = bd + d;56string bf = be + c;57string bg = bf + d;58string bh = bg + c;59string bi = bh + d;60string bj = bi + c;61string bk = bj + d;62string bl = bk + c;63string bm = bl + d;
CharPair
Using AI Code Generation
1using WinAppDriverUIRecorder;2{3 {4 static void Main(string[] args)5 {6 CharPair charPair = new CharPair();7 string s = charPair.GenerateCharPair("Ctrl+Alt+D");8 Console.WriteLine(s);9 }10 }11}12using WinAppDriverUIRecorder;13{14 {15 static void Main(string[] args)16 {17 CharPair charPair = new CharPair();18 string s = charPair.GenerateCharPair("Ctrl+Alt+D");19 Console.WriteLine(s);20 }21 }22}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!