在我的Codeception方案中,我想检查是否在提交带有某些用户错误的表单(例如,确认错误的电子邮件)时,浏览器显示带有我的自定义消息的工具提示。
HTML
<form ... >
<label>Email *</label>
<p>
<input type="email" name="email" id="email placeholder="Please insert your email" required="1" autocomplete="off" />
<input type="email" name="email_r" id="email_r" placeholder="Please confirm your email" required="1" autocomplete="off" />
</p>
</form>
JS
MyPlugin.checkMatch = function (idInputReferring, idInputRepeat){
var inputReferring = document.getElementById( idInputReferring );
var inputRepeat = document.getElementById( idInputRepeat );
if (inputReferring.value !== inputRepeat.value) {
inputRepeat.setCustomValidity( "It is must match with the previous input" );
inputRepeat.checkValidity();
setTimeout(function() {
inputRepeat.reportValidity();
}, 1);
} else {
inputRepeat.setCustomValidity('');
inputRepeat.checkValidity();
}
};
我该怎么做?
答案 0 :(得分:0)
您可以从输入元素的validationMessage
属性中获取工具提示错误消息。
答案 1 :(得分:0)
一种解决方案(但不能证明浏览器显示了工具提示):
$I->executeJS('return document.getElementById("email_r").validity.invalid;');
$I->executeJS('return jQuery("#email_r").validationMessage === "It is must match with the previous input"');