2

I've stuck with this problem as I am new to webdriverio. My requirement is I have a page which contains list of items(like buttons etc.) and I need to click each item one by one. But after clicking each item it will redirect to another section/page. And there is a "closebutton" to get back to first page(which contains list of items).

My actual requirement is webdriverclient has to click the button and it will go to respected page then click the "closebutton" and comeback and click first button and it will continue until all the buttons completed.(I've used 'async' module here)

The Code goes here..

var webdriverio = require('webdriverio');
var async = require("async");
var options = {
    desiredCapabilities: {
        browserName: 'chrome'
    }
};
var client = webdriverio.remote(options);
client
    .init()
    .url('pagelink')
    .elements('li', function (err, res) {
        if (err) {
            console.log(err);
        } else {
            var i = res.value.length;
            async.each(res.value, function (oneResult, callback) {
                console.log('i value = ' + i);
                client
                    .pause(5000).then(function () {
                        console.log('Waiting for ..... i = ' + i);
                        client
                            .element('li :nth-Child(' + i + ')').click('#button').then(function () {
                                console.log('I do .....' + i);
                                client
                                    .pause(3000).then(function (time) {
                                        console.log('Waiting for 3 sec....');
                                        client
                                            .click('.closeBtn').then(function (err, res) {
                                                console.log('Coming Back');
                                            });
                                    });
                            });
                    });
                i--;
            }, function (err) {
                if (err) {
                    console.log('A processing failed to process. ' + err);
                } else {
                    console.log('All results have been processed successfully');
                }
            });
        }
    })
    .end();
chikku
  • 863
  • 1
  • 7
  • 19
  • I too faced a similar situation. Use function calls to iterate over the elements that are returned. This will give a control over the flow - so you can freely switch through opening multiple mails. – Shashank Dec 01 '15 at 09:34

1 Answers1

0

I'm relatively new to webdriverio (a month), and I had tried what you did, but found out that the paradigm for webdriverio should be more like.

client
    .click('li :nth-Child(' + i + ')')
    .waitForExist('.closeBtn')
    .click('.closeBtn')
    .waitForExist('.uniq_to_first_page');
garajo
  • 736
  • 4
  • 19