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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17731281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 00:24:01  来源:igfitidea点击:

Wait for element to load when testing an iOS app using Appium and Ruby?

iosrubyappium

提问by Aaron Shaver

I am testing an iOS app, and can't interact with the elements after logging in because Appium is going too fast.

我正在测试一个 iOS 应用程序,登录后无法与元素进行交互,因为 Appium 运行速度太快。

Can someone please point me to an example of using a WebDriverWait style of waiting for Appium iOS testing? Preferably in Ruby.

有人可以给我指出一个使用 WebDriverWait 风格等待 Appium iOS 测试的例子吗?最好在 Ruby 中。

Thanks.

谢谢。

回答by user1919861

This worked for me but I am new to Appium

这对我有用,但我是 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

回答by Dmitry

I use this construction to wait some element appears:

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

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

Of course, you can find not only by :xpath.

当然,您不仅可以通过:xpath.

Also you can set timeout:

您也可以设置超时:

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

回答by plosco

Here is the one I came up with, but in java. A little drawn out but it walks you through how it should wait. It will take in a wait time in seconds and then check every second to see if the element is present yet. Once it has located the element it makes sure that it is visible so it can be interacted with. "driver" is obviously the WebDriver object.

这是我想出的,但在 java.lang. 有点拉长,但它会引导您了解它应该如何等待。它将花费以秒为单位的等待时间,然后每秒检查一下元素是否存在。一旦它找到了元素,它就会确保它是可见的,以便可以与之交互。“驱动程序”显然是 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));
}

回答by user2285818

I use this solutions in appium java:

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

  • Thread.sleep(1000);

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

  • Thread.sleep(1000);

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