等待特定元素出现(Appium,Java)

时间:2015-07-14 23:22:20

标签: java ios eclipse automation appium

因此,对于我的自动化程序,我需要计算广告播放所需的时间。我这样做的方法是使用一个名为timeStart = System.NanoTime()的变量;另一个名为estimatedTime = System.NanoTime() - timeStart。

现在,我的问题是如何正确告诉它等待?当我运行我的代码时,我确实得到了一个结果,但它也打印出结果,即使小文本字段还没有出现在左侧。我在这里看了一些解决方案,这就是我现在所拥有的。但我仍然不肯定它完全做我需要的。

因此,简洁的问题是:如何告诉我的应用程序不断等待并搜索对象和/或xCode的特定名称(假设它不会花费太长时间),而不会抛出ElementNotFound异常?

以下是我的代码:

public static void timerForAd(Logger logger, IOSDriver driver) throws InterruptedException
{

    WebDriverWait wait = new WebDriverWait(driver, 30);

    //String pathWay = "//UIAApplication[1]/UIAWindow[2]/UIAScrollView[1]/UIAWebView[1]/UIAStaticText[2]"; 

    long estimatedTime;

    try
    {
        synchronized(driver)
        { 

            startTime = System.nanoTime();
            wait.until(ExpectedConditions.invisibilityOfElementLocated(By.name("Ad")));
        }

        estimatedTime = System.nanoTime() - startTime;
        logger.info("Estimated Time for the the Ad to play is: " + estimatedTime);


    }catch(Exception E)
    {
        logger.info("Exception occured in timerForAd method, see if you can fix it.");
        E.printStackTrace();
    }



}

非常感谢您的帮助。

0 个答案:

没有答案