Automation 出现问题的WinAppDriver在驱动程序更改过多时识别驱动程序中的元素

Automation 出现问题的WinAppDriver在驱动程序更改过多时识别驱动程序中的元素,automation,winappdriver,Automation,Winappdriver,例如:在桌面上启动Outlook。注意这里有一个“启动加载屏幕”,我的驱动程序会查看这个可执行文件并等待x秒,然后尝试单击“新建电子邮件”按钮。但是,当它到达新的电子邮件按钮出现的页面时,它找不到它。奇怪。。。嗯,好的,让我们启动应用程序,但是让它触发已经在过程中的可执行文件。它寻找新的电子邮件按钮,发现它没有问题 我能想到的唯一一件事是,驱动程序加载可执行文件,然后可执行文件急剧更改其数据或其他内容。然后突然我需要建立一个新的驱动程序。但我不认为这是解决问题的办法 [TestInitializ

例如:在桌面上启动Outlook。注意这里有一个“启动加载屏幕”,我的驱动程序会查看这个可执行文件并等待x秒,然后尝试单击“新建电子邮件”按钮。但是,当它到达新的电子邮件按钮出现的页面时,它找不到它。奇怪。。。嗯,好的,让我们启动应用程序,但是让它触发已经在过程中的可执行文件。它寻找新的电子邮件按钮,发现它没有问题

我能想到的唯一一件事是,驱动程序加载可执行文件,然后可执行文件急剧更改其数据或其他内容。然后突然我需要建立一个新的驱动程序。但我不认为这是解决问题的办法

[TestInitialize]
public void TestMethod1()
{            
    options.AddAdditionalCapability("app", @"C:\Program Files (x86)\<PATH>");
    _driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), options);
    System.Threading.Thread.Sleep(5000); 
}

[TestMethod]
public void TEST()
{
    LoginPage page = new LoginPage(new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), options)); // Notice how i am building a new driver just for this page.  This is VERY heavy.
    page.Login("USERNAME", "PASSWORD");
}
[测试初始化]
公共void TestMethod1()
{            
options.AddAdditionalCapability(“应用程序”,@“C:\ProgramFiles(x86)\”;
_驱动程序=新的Windows驱动程序(新Uri(“http://127.0.0.1:4723",期权),;
系统线程线程睡眠(5000);
}
[测试方法]
公开无效测试()
{
登录页面=新登录页面(新Windows驱动程序(新Uri)(“http://127.0.0.1:4723“”,options));//注意我是如何为这个页面构建一个新的驱动程序的。这非常繁重。
登录页面(“用户名”、“密码”);
}
您可能有“启动屏幕问题”。 关于如何处理它的解释

简而言之,winappdriver为遇到的每个新窗口创建一个新的windowhandle。由于启动屏幕是一个单独的窗口,在您想要单击“新建电子邮件”按钮时,您应该有两个可用的窗口句柄。最新的windowhandle将是最高索引

您可以在如下窗口句柄之间切换(从链接复制):

再看看答案。也可能有用

// Return all window handles associated with this process/application.
// At this point hopefully you have one to pick from. Otherwise you can
// simply iterate through them to identify the one you want.
var allWindowHandles = session.WindowHandles;
// Assuming you only have only one window entry in allWindowHandles and it is in fact the correct one,
// switch the session to that window as follows. You can repeat this logic with any top window with the same²
// process id (any entry of allWindowHandles)
session.SwitchTo().Window(allWindowHandles[0]);