Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I'm trying to use isVisible() within a loop to create a waitForElement type of a function for my iOS UIAutomation. When I try to use the following code, it fails while waiting for an element when a new screen pops up. The element is clearly there because if I do a delay(2) before tapping the element it works perfectly fine. How is everyone else accomplishing this, because I am at a loss...

Here's the waitForElement code that I am using:

function waitForElement(element, timeout, step) {
        if (step == null) {
                step = 0.5;
        }

        if (timeout == null) {
            timeout = 10;
        }

        var stop = timeout/step;

        for (var i = 0; i < stop; i++) {
                if (element.isVisible()) {
                        return;
                }
                target.delay(step);
        }
        element.logElement();
        throw("Not visible");
}
share|improve this question
    
What if you check for existence before checking for visibility: if exists {if visible: return} –  Suchit Parikh Oct 23 '12 at 19:52

2 Answers 2

If your page reloads during waitForElement function execution then you have to refresh element by finding it once again. Try to use selector as parameter an not the element and use findElement function:

function waitForElement(selector, timeout, step) {
        if (step == null) {
                step = 0.5;
        }

        if (timeout == null) {
            timeout = 10;
        }

        var stop = timeout/step;

        for (var i = 0; i < stop; i++) {
                if (driver.findElement(selector).isVisible()) {
                        return;
                }
                target.delay(step);
        }
        element.logElement();
        throw("Not visible");
}
share|improve this answer

This waiting should be handled for you. You can specify isVisible using a predicate or withValueForKey Try this ...

target.pushTimeout(timeout); element.withValueForKey(1, "isVisible"); target.popTimeout();

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.