11

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

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

Thanks.

Aaron
  • 2,154
  • 5
  • 29
  • 42
  • Looking for exactly the same thing either in ruby or js. – jdrm Jul 19 '13 at 03:45
  • I'm also looking for the same thing. For android, something like `browser.driver.manage.timeouts.page_load = 30` seems to work. On iOS an error pops up saying that Appium hasn't implemented that... – David West Sep 10 '13 at 16:51

4 Answers4

14

This worked for me but I am new to 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
user1919861
  • 156
  • 3
  • 1
    This is a good example if you're certain that the element shall load in 10 seconds. Otherwise (e.g. the name changed, or not enough time) it'll throw exception Selenium::WebDriver::Error::NoSuchElementError: No element found and you should rescue it somehow. – Clergyman Oct 16 '14 at 11:57
  • `sleep(10)` is similar to this. How is this different ? – Emjey Apr 11 '17 at 12:34
  • @Mrityunjeyan S - The `wait` with `timeout => 10` will delay execution up to 10 seconds, but will stop delaying if the expected condition becomes true (once the element is displayed, in this case). However a `sleep(10)` will delay execution for exactly 10 seconds regardless. – Dingredient Jun 12 '17 at 04:01
6

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.

Also you can set timeout:

wait_true(timeout) { exists { find_element(:xpath, path_to_element) } }
Dmitry
  • 351
  • 1
  • 4
  • 10
5

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.

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));
}
plosco
  • 891
  • 1
  • 10
  • 18
3

I use this solutions in appium java:

  • Thread.sleep(1000);

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

Ankur
  • 5,086
  • 19
  • 37
  • 62