自动浏览器不提交表单

时间:2018-07-03 11:53:56

标签: node.js selenium testing automated-tests nightwatch.js

我目前正在使用Selenium和Nightwatch.js对Browserstack进行自动化测试。我遇到无法提交登录表单的问题。没有任何反应或只是重新加载页面。使用browser.setValue('{selector}', '{value}')设置所有必需的登录数据。在Chrome和Firefox上进行了尝试,但结果相同。不过,我可以在浏览器控制台中使用JS提交表单。

我尝试了以下方法,但无济于事。

browser.submitForm('#login-form');
browser.click('#send2');
browser.execute("document.getElementById('send2').click();");
browser.execute("document.getElementById('login-form').submit();");

有什么我想念的吗?如果有什么不同,我正在尝试自动执行Magento 1网站的登录表单。

非常感谢。

编辑: 添加了表单HTML

<form action="https://{site}/en/customer/account/loginPost/" method="post" id="login-form">
							<input name="form_key" type="hidden" value="1CdZGL4mwA0njx3U">		        	        
							<div class="form-group">
								<input type="text" class="input-text-custom required-entry validate-email form-control" id="email" name="login[username]" value="" title="Insert Email Address" placeholder="Insert Email Address">					    
							</div>		        
							<div class="form-group">						
								<input type="password" class="input-text-custom required-entry form-control" id="pass" name="login[password]" title="Password" placeholder="Password">											    
							</div>
                            <div class="form-group">
                                <input type="checkbox" name="nl_subscribe" id="nl_subscribe_existing" value="subscribe" class="form-control checkbox">
                                <label for="nl_subscribe_existing" class="text-normal-checkout"><span></span>By the way, I also want to subscribe to your newsletter*</label>
                            </div>
                            <input type="hidden" name="nl_source" value="customer_login" class="form-control checkbox">
				                                        <div class="form-group"><div class="control remember-me-box">
        <div class="input-box">
        <input type="checkbox" name="persistent_remember_me" class="checkbox" id="remember_meL0h6snrk30" title="Remember Me">
        <label for="remember_meL0h6snrk30" class="text-normal-checkout"><span></span>Remember Me</label>
    </div>
</div>
</div>
					        <div class="forgot-password"><a href="https://{site}/en/customer/account/forgotpassword/">Forgot password?</a></div>
                            <div align="center"><button type="submit" class="button-check" name="send" id="send2" title="log in"><span><span>log in</span></span></button></div>
</form>

修改2: 这可能与配置有关吗?我在本地浏览器上启动了此测试,然后将其停止,因此我可以手动填写并提交表单,但无论如何我都无法提交。

1 个答案:

答案 0 :(得分:0)

该脚本似乎很好,但是网站中存在错误。由于某种原因,脚本需要刷新浏览器才能成功提交表单。因此,在解决此问题之前,我已经实现了browser.execute('location.reload();');作为解决方法。

相关问题