早教吧 育儿知识 作业答案 考试题库 百科 知识分享

从一记事本中复制某一公式到计算器中完成一个小自动化测试,为什么下面的代码总是报错呢?startInfo=newProcessStartInfo(@"C:\Users\zou\Desktop\formula.txt");startInfo.WindowStyle=ProcessWindowStyle.Normal;startInf

题目详情
从一记事本中复制某一公式到计算器中完成一个小自动化测试,为什么下面的代码总是报错呢?
startInfo = new ProcessStartInfo(@"C:\Users\zou\Desktop\formula.txt");
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.UseShellExecute = true;
process = Process.Start(startInfo);
Thread.Sleep(1000);
windowHandle = process.MainWindowHandle;
AutomationElement notepod = AutomationElement.FromHandle(windowHandle);
string EditMenuAutomationId = "Item 2";
propertyCondition = new PropertyCondition(AutomationElement.AutomationIdProperty,EditMenuAutomationId);
editMenu = notepod.FindFirst(TreeScope.Element | TreeScope.Descendants,propertyCondition);
if (editMenu == null)
{
Console.WriteLine(EditMenuAutomationId.ToString() + " could not be found.");
return;
}
if ((bool)editMenu.GetCurrentPropertyValue(AutomationElement.IsEnabledProperty) == false)
{
Console.WriteLine("Element not enabled.");
return;
}
expandEdit = editMenu.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
expandEdit.Expand();
//select all
AutomationElement automationelementname1 = notepod.FindFirst(TreeScope.Element | TreeScope.Descendants,propertyCondition);
program.ButtonClick(automationelementname1,"Item 25");
//copy
expandEdit = editMenu.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
expandEdit.Expand();
program.ButtonClick(automationelementname1,"Item 769");
process.Close();
调用的方法:
public void ButtonClick(AutomationElement AutomationElementname,string AutomationId)
{
propertyCondition = new PropertyCondition(AutomationElement.AutomationIdProperty,AutomationId);
AutomationElementname = calculator.FindFirst(TreeScope.Element | TreeScope.Descendants,propertyCondition);
if (AutomationElementname == null)
{
Console.WriteLine(AutomationId.ToString() + " could not be found.");
return;
}
if ((bool)AutomationElementname.GetCurrentPropertyValue(AutomationElement.IsEnabledProperty) == false)
{
Console.WriteLine("Element not enabled.");
return;
}
invokePattern = AutomationElementname.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
invokePattern.Invoke();
Thread.Sleep(1000);
}
▼优质解答
答案和解析
用记事本把这段代码复制过去,然后另存为.frm就可以了
VERSION 5.00
Begin VB.Form frmMain
Appearance = 0 'Flat
BackColor =
看了 从一记事本中复制某一公式到计...的网友还看了以下:

传感器可将非电学量转化为电学量,起自动控制作用.如计算机鼠标中有位移传感器,电熨斗、电饭煲中有温度  2020-05-15 …

通过分析被评估资产的相关收入和成本费用,将未来收益折现或资本化为估算价值的评估方法是  2020-05-19 …

怎样用计算器把小数化为度数比如输入tan-1√3显示的是1/3π怎么转化成度数呢用计算器  2020-05-22 …

美国布朗大学的约翰•唐纳德首次成功将瘫痪病人的大脑信号转化为计算机代码,让一位因中风而丧失四肢活动  2020-07-02 …

用普通计算器将角度化为长度在正弦定理中,比如10°化为长度cm,用计算器怎么化比如sin10°化为  2020-08-02 …

(2008•南平)小明家新买了一台太阳能热水器,请回答并计算下列问题:(1)太阳能热水器工作时,是将  2020-11-12 …

为了响应“节能减排”的号召,小周家买了一台容积为100L,受热面积为1.5平方米的太阳能热水器,请你  2020-11-25 …

传感器可将非电学量转化为电学量,起自动控制作用.如计算机鼠标中有位移传感器,电熨斗、电饭煲中有温度传  2020-12-22 …

传感器可将非电学量转化为电学量,起自动控制作用.如计算机鼠标中有位移传感器,电熨斗、电饭煲中有温度传  2020-12-22 …

化学计算题..在一个密闭容器中,(容器为5L).充入氮气和氧气.使其物质的量之比为1;2.并发生如下  2021-02-16 …