Возможно ли при помощи метода fillSelectors
указать какой из radio button нужно установить checked
? Желательно по значению атрибута value
в radio button.
"use strict";
var casper = require('casper').create();
var faker = require('./../../libs/faker.min.js');
var utils = require('utils');
/**
* Define custom faker methods.
*/
faker.internet.emailName = function(limit) {
var text = "";
var possible = "abcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < limit; i++) text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
};
faker.internet.email2 = function(limit) {
return faker.internet.emailName(limit) + '@' + faker.random.arrayElement(['mail.ru', 'bk.ru', 'inbox.ru', 'list.ru', 'mail.ua']);
};
// Account data.
var account = {
username: faker.internet.email2(20),
firstname: faker.name.firstName(),
lastname: faker.name.lastName(),
gender: faker.random.arrayElement([1, 2]),
birthday: Math.floor(Math.random() * 31) + 1,
birthdaymonth: Math.floor(Math.random() * 12) + 1,
birthyear: Math.floor(Math.random() * (new Date().getFullYear() - 1920) + 1910)
};
// Registration page.
casper.start('https://m.mail.ru/cgi-bin/reg', function() {
this.echo('Fill form data:');
utils.dump(account);
var genderName = this.evaluate(function() {
return document.querySelector('form.reg_form input[type=radio]').name;
});
this.fillSelectors('form.reg_form', {
'input#Username': account.username,
//'' : account.firstname,
//'' : account.lastname,
genderName: account.gender,
'input.birthday': account.birthday,
'select[name=BirthMonth]': account.birthdaymonth.toString(),
'input.birthyear': account.birthyear
}, true);
});
casper.then(function() {
this.capture("page.png");
});
casper.run();
<form method="post" action="reg" class="reg_form">
<input type="hidden" name="MultistepMobileReg" value="1">
<input type="hidden" name="ID" value="mG2cM653">
<input type="hidden" name="Count" value="1">
<input type="hidden" name="back" value="/cgi-bin/folders">
<input type="hidden" name="browserData" value="NoJS">
<input type="hidden" name="lang" value="">
<input type="hidden" name="x_reg_id" value="wRYPrNHNAFfiEX5D">
<p>
<label for="Username" class="name">Придумайте название почты</label>
<input type="text" id="Username" name="x_a71af1677afab5a8" value="" maxlength="31">
</p>
<p>
<select name="RegistrationDomain" class="mr">
<option value="mail.ru" selected="">@mail.ru</option>
<option value="bk.ru">@bk.ru</option>
<option value="inbox.ru">@inbox.ru</option>
<option value="list.ru">@list.ru</option>
<option value="mail.ua">@mail.ua</option>
</select>
</p>
<img src="//rs.mail.ru/d609920.gif" alt="" style="position: absolute;" width="1" height="1">
<p>
<label for="id-x_1de3798ee0d1750b" class="name">Имя</label>
<input type="text" id="id-x_1de3798ee0d1750b" name="x_1de3798ee0d1750b" value="" maxlength="20">
</p>
<p>
<label for="id-x_a51e3e43bb47050f" class="name">Фамилия</label>
<input type="text" id="id-x_a51e3e43bb47050f" name="x_a51e3e43bb47050f" value="" maxlength="40">
</p>
<p>
<label class="name">Пол</label>
<label class="pb" for="id-x_9d697afa1027656b-1">
<input type="radio" id="id-x_9d697afa1027656b-1" name="x_9d697afa1027656b" value="1"> <span class="label">Мужской</span>
</label>
<br>
<label class="pb" for="id-x_9d697afa1027656b-2">
<input type="radio" id="id-x_9d697afa1027656b-2" name="x_9d697afa1027656b" value="2"> <span class="label">Женский</span>
</label>
<br>
</p>
<p>
<label class="name" for="id-x_c47a6e96daa7ce36">
День рождения</label>
<input type="number" min="1" max="31" step="1" class="birthday" name="x_c47a6e96daa7ce36" value="" size="2" placeholder="ДД">
<select name="BirthMonth">
<option value="">месяц</option>
<option value="1">Январь</option>
<option value="2">Февраль</option>
<option value="3">Март</option>
<option value="4">Апрель</option>
<option value="5">Май</option>
<option value="6">Июнь</option>
<option value="7">Июль</option>
<option value="8">Август</option>
<option value="9">Сентябрь</option>
<option value="10">Октябрь</option>
<option value="11">Ноябрь</option>
<option value="12">Декабрь</option>
</select>
<input type="number" min="1910" max="2016" step="1" class="birthyear" name="x_96bf963a7794f06c" value="" size="4" placeholder="ГГГГ">года
</p>
<input type="hidden" name="SavePost" value="1">
<input type="hidden" name="RegStep" value="1">
<input type="hidden" name="load" value="">
<p class="button">
<input type="submit" value="Далее">
</p>
</form>