使用Appium和Ruby测试iOS应用程序时是否等待加载元素?

时间:2013-07-18 18:30:15

标签: ios ruby appium

我正在测试iOS应用,并且在登录后无法与元素交互,因为Appium的速度太快了。

有人可以指点我使用WebDriverWait样式等待Appium iOS测试吗?最好是在Ruby中。

感谢。

4 个答案:

答案 0 :(得分:13)

这对我有用,但我是Appium的新手

#code that navigated to this page
wait = Selenium::WebDriver::Wait.new :timeout => 10
wait.until { @driver.find_element(:name, 'myElementName').displayed? }
#code that deals with myElementName

答案 1 :(得分:6)

我使用这种结构来等待出现一些元素:

wait_true { exists { find_element(:xpath, path_to_element) } }

当然,您不仅可以通过:xpath找到。

您也可以设置超时:

wait_true(timeout) { exists { find_element(:xpath, path_to_element) } }

答案 2 :(得分:5)

这是我提出的那个,但是在java中。有点抽出,但它会引导您了解它应该如何等待。它将在几秒钟内等待,然后每秒检查一次,看看元素是否存在。一旦找到元素,它就会确保它是可见的,这样它就可以与之交互。 “driver”显然是WebDriver对象。

public void waitForVisible(final By by, int waitTime) {
    wait = new WebDriverWait(driver, timeoutInSeconds);
    for (int attempt = 0; attempt < waitTime; attempt++) {
        try {
            driver.findElement(by);
            break;
        } catch (Exception e) {
            driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
        }
    }
    wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}

答案 3 :(得分:3)

我在appium java中使用这个解决方案:

  • Thread.sleep(1000);

  • WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.elementToBeClickable(By.name("somename")));