AlenSv
AlenSv

Reputation: 125

How to wait until element's text had changed in WebdriverJS?

I've found in Alister Scott's blog how to wait until element had changed to specific value. But I can't solve problem with how to create waiting for element to wait until its text had changed FROM specific value (in my case from '-') to anything else (in my case it's a counter, so I can't set specific value to wait for).

Any ideas?

Upvotes: 1

Views: 2309

Answers (2)

Tiago Bértolo
Tiago Bértolo

Reputation: 4363

If you are new to Promises it may get a bit confusing...

driver.wait(function () {
    return driver.findElement(By.id('idYouWant')).getText().then(function (text) {
        return text === 'Done';
    });
}, timeout);

This bit of code monitors the text of a dynamically changing element with a given ID.

Notice the 2 returns and remember that the timeout is in milliseconds.

Upvotes: 2

Slava Shpitalny
Slava Shpitalny

Reputation: 4195

You can save the existing value before the change, after that you can supply your own expectation function to the wait method. Your function should return true when the value is different from the old value.

var oldValue = ...;
driver.wait(function(){
    var newValue = ...;
    return newValue != oldValue;
}, timeout);

Upvotes: 1

Related Questions