“控制。存在”循环内第一次在编码的用户界面中工作,而不是第二次 [英] "control.Exists" within a loop works for first time and not for second time in coded ui

查看:68
本文介绍了“控制。存在”循环内第一次在编码的用户界面中工作,而不是第二次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑代码

for(i = 0; i < 5; i++)
{
    if(control.Exists)
    {
        mouse.Click(button);
    }
}

在此,控件是一个弹出窗口。第一次执行时,control.Exists = true,第二次则为false,尽管存在控件。为什么?

In this, control is a popup window. for the first time of execution, control.Exists = true and for the second time it is false though the control is present. Why is that so? How to make it to be true?

预先感谢。

推荐答案

程序通常会绘制控件的另一个副本,它看上去与眼睛相同,但有所不同。因此,第二次循环 control 引用了该控件的旧版本,但不再存在。

Programs often draw another copy of a control, it looks identical to the eye but it is different. Hence the second time around the loop control refers to the old version of the control but it is no longer present.

您的代码可能等效于

for(i = 0; i < 5; i++)
{
    if(top.middle.control.Exists)
    {
        mouse.Click(top.middle.button);
    }
}

UI控件层次结构中的级别可能更多,但

There may be more levels in the UI Control hierarchy but three is enough for the explaination here.

通常的解决方法是在使用控件之前先找到该控件的新副本。因此将代码更改为

The normal fix is to find the new copy of the control before using it. So change the code to be

for(i = 0; i < 5; i++)
{
    top.middle.Find();
    if(top.middle.control.Exists)
    {
        mouse.Click(top.middle.button);
    }
}

如果这不起作用,因为中间也不可用,然后使用 top.Find();

If that does not work, because middle is also not available, then use top.Find();.

要了解有关哪些控件可用或不可用的更多信息,请尝试这样的代码,并观察屏幕的哪些部分用蓝色框突出显示。

To learn more about which controls are available or not, try code like this and observe which parts of the screen are highlighted with blue boxes.

for(i = 0; i < 5; i++)
{
    top.DrawHighLight();
    top.middle.DrawHighLight();
    top.middle.control.DrawHighLight();
    if(top.middle.control.Exists)
    {
        mouse.Click(top.middle.button);
    }
}

这篇关于“控制。存在”循环内第一次在编码的用户界面中工作,而不是第二次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆