0

我创建了一个实用程序类,其中有:

public void waitForScreenToLoad(AndroidDriver  lDriver, WebElement element, int seconds){
    WebDriverWait wait = new WebDriverWait(lDriver,seconds);
    wait.until(ExpectedConditions.visibilityOf(element));
}

我的主要登录类别有:

@Test (priority = 0)
public void SignIn() throws InterruptedException, IOException {
    Thread.sleep(8000);
    MobileElement ele = (MobileElement) driver.findElementByAccessibilityId("abcde");
    MobileElement sign = (MobileElement) driver.findElementByAccessibilityId("Sign in");
    sign.click();
    // Thread.sleep(8000);
    waitForScreenToLoad(driver, ele, 120);
    captureScreenshot(driver,folder_name,df);   
    Thread.sleep(2000);
}

它们都在同一个包中。元素ele在登录前后的两个页面上都存在。等待不起作用,但是,如果我使用Thread.sleep它,我可以截屏。

谁能告诉我我的代码有什么问题?或者如果Thread.sleep经常使用可以让它工作?

4

1 回答 1

1

ele单击并重新加载页面后已过时。尝试使用另一个预期条件。

public void waitForScreenToLoad(AndroidDriver  lDriver, By locator, int seconds)
        {

                WebDriverWait wait = new WebDriverWait(lDriver,seconds);
                wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
          }


@Test (priority = 0)
  public void SignIn() throws InterruptedException, IOException {
            Thread.sleep(8000);
            //MobileElement ele = (MobileElement) driver.findElementByAccessibilityId("abcde");
            By ele_locator = By.AccessibilityId("abcde");
            MobileElement sign = (MobileElement) driver.findElementByAccessibilityId("Sign in");
            sign.click();
           // Thread.sleep(8000);
            waitForScreenToLoad(driver, ele_locator, 120);
            captureScreenshot(driver,folder_name,df);   
            Thread.sleep(2000);
于 2018-03-28T13:56:24.583 回答