Best WinAppDriver code snippet using AbsoluteXPath.Calculator
Calculator.cs
Source:Calculator.cs
...17using Microsoft.VisualStudio.TestTools.UnitTesting;18namespace AbsoluteXPath19{20 [TestClass]21 public class Calculator22 {23 [TestMethod]24 public void TestMethod1()25 {26 DesktopSession desktopSession = new DesktopSession();27 TimeSpan.FromSeconds(2);28 bool bSuccess = false;29 try30 {31 // LeftClick on Button "Type here to search" at (95,20)32 Console.WriteLine("LeftClick on Button \"Type here to search\" at (95,20)");33 string xpath_LeftClickButtonTypehereto_95_20 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Pane[@ClassName=\"Shell_TrayWnd\"][@Name=\"Taskbar\"]/Pane[@ClassName=\"TrayDummySearchControl\"]/Button[@ClassName=\"Button\"][@Name=\"Type here to search\"]";34 var winElem_LeftClickButtonTypehereto_95_20 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonTypehereto_95_20);35 if (winElem_LeftClickButtonTypehereto_95_20 != null)36 {37 winElem_LeftClickButtonTypehereto_95_20.Click();38 }39 else40 {41 Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonTypehereto_95_20}");42 return;43 }44 // KeyboardInput VirtualKeys=""calculator"" CapsLock=False NumLock=False ScrollLock=False45 Console.WriteLine("KeyboardInput VirtualKeys=\"\"calculator\"\" CapsLock=False NumLock=False ScrollLock=False");46 System.Threading.Thread.Sleep(1000);47 winElem_LeftClickButtonTypehereto_95_20.SendKeys("calculator");48 // LeftClick on ListItem "Calculator, Trusted Microsoft Store app, Press right to switch p" at (113,27)49 Console.WriteLine("LeftClick on ListItem \"Calculator, Trusted Microsoft Store app, Press right to switch p\" at (113,27)");50 string xpath_LeftClickListItemCalculator_113_27 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Cortana\"]/Pane[@ClassName=\"WebView\"][@Name=\"Bing\"]/Pane[@Name=\"Bing\"]/List[@Name=\"Results\"][@AutomationId=\"suggestionsList\"]/ListItem[starts-with(@Name,\"Calculator, Trusted Microsoft Store app, Press right to switch p\")][starts-with(@AutomationId,\"id_\")]";51 var winElem_LeftClickListItemCalculator_113_27 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickListItemCalculator_113_27);52 if (winElem_LeftClickListItemCalculator_113_27 != null)53 {54 winElem_LeftClickListItemCalculator_113_27.Click();55 }56 else57 {58 Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickListItemCalculator_113_27}");59 return;60 }61 // LeftClick on Button "One" at (41,16)62 Console.WriteLine("LeftClick on Button \"One\" at (41,16)");63 string xpath_LeftClickButtonOne_41_16 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Calculator\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Calculator\"]/Group[@ClassName=\"LandmarkTarget\"]/Group[@Name=\"Number pad\"][@AutomationId=\"NumberPad\"]/Button[@Name=\"One\"][@AutomationId=\"num1Button\"]";64 var winElem_LeftClickButtonOne_41_16 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonOne_41_16);65 if (winElem_LeftClickButtonOne_41_16 != null)66 {67 winElem_LeftClickButtonOne_41_16.Click();68 }69 else70 {71 Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonOne_41_16}");72 return;73 }74 // LeftClick on Button "Plus" at (52,24)75 Console.WriteLine("LeftClick on Button \"Plus\" at (52,24)");76 string xpath_LeftClickButtonPlus_52_24 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Calculator\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Calculator\"]/Group[@ClassName=\"LandmarkTarget\"]/Group[@ClassName=\"NamedContainerAutomationPeer\"][@Name=\"Standard operators\"]/Button[@Name=\"Plus\"][@AutomationId=\"plusButton\"]";77 var winElem_LeftClickButtonPlus_52_24 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonPlus_52_24);78 if (winElem_LeftClickButtonPlus_52_24 != null)79 {80 winElem_LeftClickButtonPlus_52_24.Click();81 }82 else83 {84 Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonPlus_52_24}");85 return;86 }87 // LeftClick on Button "Two" at (58,28)88 Console.WriteLine("LeftClick on Button \"Two\" at (58,28)");89 string xpath_LeftClickButtonTwo_58_28 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Calculator\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Calculator\"]/Group[@ClassName=\"LandmarkTarget\"]/Group[@Name=\"Number pad\"][@AutomationId=\"NumberPad\"]/Button[@Name=\"Two\"][@AutomationId=\"num2Button\"]";90 var winElem_LeftClickButtonTwo_58_28 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonTwo_58_28);91 if (winElem_LeftClickButtonTwo_58_28 != null)92 {93 winElem_LeftClickButtonTwo_58_28.Click();94 }95 else96 {97 Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonTwo_58_28}");98 return;99 }100 // LeftClick on Button "Equals" at (56,27)101 Console.WriteLine("LeftClick on Button \"Equals\" at (56,27)");102 string xpath_LeftClickButtonEquals_56_27 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Calculator\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Calculator\"]/Group[@ClassName=\"LandmarkTarget\"]/Group[@ClassName=\"NamedContainerAutomationPeer\"][@Name=\"Standard operators\"]/Button[@Name=\"Equals\"][@AutomationId=\"equalButton\"]";103 var winElem_LeftClickButtonEquals_56_27 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonEquals_56_27);104 if (winElem_LeftClickButtonEquals_56_27 != null)105 {106 winElem_LeftClickButtonEquals_56_27.Click();107 }108 else109 {110 Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonEquals_56_27}");111 return;112 }113 // LeftClick on Text "Display is 3" at (472,2)114 Console.WriteLine("LeftClick on Text \"Display is 3\" at (472,2)");115 string xpath_LeftClickTextDisplayis3_472_2 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Calculator\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Calculator\"]/Group[@ClassName=\"LandmarkTarget\"]/Text[@Name=\"Display is 3\"][@AutomationId=\"CalculatorResults\"]";116 var winElem_LeftClickTextDisplayis3_472_2 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickTextDisplayis3_472_2);117 if (winElem_LeftClickTextDisplayis3_472_2 != null)118 {119 winElem_LeftClickTextDisplayis3_472_2.Click();120 }121 else122 {123 Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickTextDisplayis3_472_2}");124 return;125 }126 // LeftClick on Button "Close Calculator" at (24,15)127 Console.WriteLine("LeftClick on Button \"Close Calculator\" at (24,15)");128 string xpath_LeftClickButtonCloseCalcu_24_15 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Calculator\"]/Window[@Name=\"Calculator\"][@AutomationId=\"TitleBar\"]/Button[@Name=\"Close Calculator\"][@AutomationId=\"Close\"]";129 var winElem_LeftClickButtonCloseCalcu_24_15 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonCloseCalcu_24_15);130 if (winElem_LeftClickButtonCloseCalcu_24_15 != null)131 {132 winElem_LeftClickButtonCloseCalcu_24_15.Click();133 }134 else135 {136 Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonCloseCalcu_24_15}");137 return;138 }139 // test complete140 bSuccess = true;141 }142 finally...
Calculator
Using AI Code Generation
1using System;2using AbsoluteXPath;3{4 {5 public int add(int a, int b)6 {7 return a + b;8 }9 public int subtract(int a, int b)10 {11 return a - b;12 }13 public int multiply(int a, int b)14 {15 return a * b;16 }17 public int divide(int a, int b)18 {19 return a / b;20 }21 }22}23using System;24using AbsoluteXPath;25{26 {27 static void Main(string[] args)28 {29 Calculator cal = new Calculator();30 Console.WriteLine("Addition of 10 and 20 is: " + cal.add(10, 20));31 Console.WriteLine("Subtraction of 10 and 20 is: " + cal.subtract(10, 20));32 Console.WriteLine("Multiplication of 10 and 20 is: " + cal.multiply(10, 20));33 Console.WriteLine("Division of 10 and 20 is: " + cal.divide(10, 20));34 Console.ReadLine();35 }36 }37}
Calculator
Using AI Code Generation
1using AbsoluteXPath;2using System;3{4 {5 static void Main(string[] args)6 {7 Calculator obj = new Calculator();8 int result = obj.Add(10, 20);9 Console.WriteLine(result);10 }11 }12}13using AbsoluteXPath;14using System;15using System.Xml;16{17 {18 static void Main(string[] args)19 {20 XmlDocument doc = new XmlDocument();21 doc.Load("Students.xml");22 XmlNode node = doc.SelectSingleNode("/Students/Student/StudentName");23 Console.WriteLine(node.InnerText);24 }25 }26}
Calculator
Using AI Code Generation
1using AbsoluteXPath;2{3 static void Main()4 {5 Calculator c = new Calculator();6 c.Add(10, 20);7 c.Subtract(10, 20);8 c.Multiply(10, 20);9 c.Divide(10, 20);10 }11}12C# | XPathNodeIterator.Clone()13C# | XPathNodeIterator.MoveNext()14C# | XPathNodeIterator.Reset()15C# | XPathNavigator.Clone()16C# | XPathNavigator.MoveToAttribute()17C# | XPathNavigator.MoveToFirstAttribute()18C# | XPathNavigator.MoveToFirstChild()19C# | XPathNavigator.MoveToFirstNamespace()20C# | XPathNavigator.MoveToFollowing()21C# | XPathNavigator.MoveToId()22C# | XPathNavigator.MoveToNext()23C# | XPathNavigator.MoveToNextAttribute()24C# | XPathNavigator.MoveToNextNamespace()25C# | XPathNavigator.MoveToParent()26C# | XPathNavigator.MoveToPrevious()27C# | XPathNavigator.MoveToRoot()28C# | XPathNavigator.MoveToSelf()29C# | XPathNavigator.MoveToFirst()30C# | XPathNavigator.MoveToNext()31C# | XPathNavigator.MoveToNext(XPathNodeType)32C# | XPathNavigator.MoveToPrevious()33C# | XPathNavigator.MoveToPrevious(XPathNodeType)34C# | XPathNavigator.MoveTo(XPathNavigator)35C# | XPathNavigator.MoveToId(string)36C# | XPathNavigator.MoveToFirstAttribute()37C# | XPathNavigator.MoveToFirstNamespace()38C# | XPathNavigator.MoveToNextAttribute()39C# | XPathNavigator.MoveToNextNamespace()40C# | XPathNavigator.MoveToFirst(XPathNodeType)41C# | XPathNavigator.MoveToNext(XPathNodeType)42C# | XPathNavigator.MoveToPrevious(XPathNodeType)43C# | XPathNavigator.MoveTo(XPathNavigator)
Calculator
Using AI Code Generation
1using AbsoluteXPath;2{3 {4 static void Main(string[] args)5 {6 Calculator calc = new Calculator();7 Console.WriteLine(calc.Add(5, 6));8 }9 }10}11using AbsoluteXPath;12{13 {14 static void Main(string[] args)15 {16 Calculator calc = new Calculator();17 Console.WriteLine(calc.Add(5, 6));18 }19 }20}
Calculator
Using AI Code Generation
1using AbsoluteXPath;2using System;3{4 static void Main()5 {6 Calculator c = new Calculator();7 Console.WriteLine(c.Add(10, 20));8 Console.WriteLine(c.Sub(20, 10));9 }10}11Relative XPath is a way to identify a node or a set of nodes in an XML document. It is a relative path that starts from the current node in the XML document. The relative XPath is a string that starts with a forward slash (/) followed by the name of the child element. It is followed by
Calculator
Using AI Code Generation
1using System;2using AbsoluteXPath;3{4 {5 static void Main(string[] args)6 {7 Calculator calc = new Calculator();8 int sum = calc.Add(10, 20);9 Console.WriteLine("Sum is = " + sum);10 Console.ReadLine();11 }12 }13}
Calculator
Using AI Code Generation
1using AbsoluteXPath;2using System;3{4static void Main(string[] args)5{6Calculator calc=new Calculator();7Console.WriteLine("Addition of 10 and 20 is "+calc.Add(10,20));8Console.WriteLine("Subtraction of 20 and 10 is "+calc.Subtract(20,10));9Console.WriteLine("Multiplication of 10 and 20 is "+calc.Multiply(10,20));10Console.WriteLine("Division of 20 and 10 is "+calc.Divide(20,10));11Console.ReadLine();12}13}
Calculator
Using AI Code Generation
1using AbsoluteXPath;2using System;3{4 {5 public static void Main(string[] args)6 {7 Calculator calc = new Calculator();8 Console.WriteLine(calc.Add(3, 4));9 Console.WriteLine(calc.Subtract(3, 4));10 Console.WriteLine(calc.Multiply(3, 4));
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!!