node.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: 这可能与配置有关吗?我在本地浏览器上启动了这个测试然后停止了它,所以我可以手动填写并提交表单,但我还是无法提交。
解决方案
脚本似乎很好,但该站点存在错误。由于某种原因,脚本需要刷新浏览器才能成功提交表单。因此,在解决此问题之前,我已经实施browser.execute('location.reload();');
了一种解决方法。
推荐阅读
- javascript - 在 Ckeditor 中,如果我输入文本或退格输入复选框将取消选中并且值将更改
- c++ - Android NDK Crashanalytics 将日志发送到 Firebase 时出错。(C++)
- flutter - 如何在颤动中解决(操作系统错误:不允许操作,errno = 1)
- pandas - Databricks 火花雪花 dataframe.toPandas() 占用更多空间和时间
- python - Serializers.validated_data 字段随 DRF 中的源值而更改
- c++ - IIS 在回收期间是否取消/注册 C++ COM 库?
- linux - 如何使用 Gmail 为 Airflow 电子邮件警报设置 SMTP 服务器
- swiftui - iOS 15 上的 SwiftUI,自定义按钮样式不再起作用,它在 iOS 14 上运行良好,如何解决?
- java - 如何返回一个 Mono 空对象,以便它被 application/json 格式接受?
- python - Pandas 与每日间隔的值的最大差异