How to perform conditional browser interactions with the internet

With the promised web driver, I would like to check if an element exists on the page and then log in if it does, otherwise continue the promise chain.

Is this possible at the moment due to https://github.com/theintern/intern/issues/14 ?

+1


source to share


1 answer


In Intern 2, just use the regular command find

:

var remote = this.remote;
remote.get(url)
    .findById('foo')
    .then(function (element) {
        // exists
    }, function () {
        // does not exist
    });

      

In Intern 1, if you need to conditionally fork, you need to stop and add new instructions based on the result of your check.



var remote = this.remote;
remote.get(url)
    .elementByIdIfExists('foo')
    .then(function (element) {
        if (element) {
            remote.clickElement()
                .type('foo');
                // ...etc.
        }
    });

      

This should work in the Intern 1.1 only if you add new commands to the remote chain of promises when there are other pre-existing teams waiting . Intern 1.2 will contain enhancements to address this limitation. This is question number 14.

+3


source







All Articles