Javascript 如何使用噩梦.js将文本输入到同一类的两个元素中
我正在使用噩梦.js自动测试登录网站,我遇到了一个问题: 用户名: 密码: 据我所知,关注这些的唯一方法是使用附加到它的类,但由于它们是相同的,所以它只关注“用户名” 这是我的密码:Javascript 如何使用噩梦.js将文本输入到同一类的两个元素中,javascript,mocha.js,nightmare,Javascript,Mocha.js,Nightmare,我正在使用噩梦.js自动测试登录网站,我遇到了一个问题: 用户名: 密码: 据我所知,关注这些的唯一方法是使用附加到它的类,但由于它们是相同的,所以它只关注“用户名” 这是我的密码: const Nightmare = require("nightmare"); const assert = require("assert"); describe("Login Page", function() { this.timeout("30s"); let nightmare = null;
const Nightmare = require("nightmare");
const assert = require("assert");
describe("Login Page", function() {
this.timeout("30s");
let nightmare = null;
beforeEach(() => {
nightmare = new Nightmare({ show: true });
});
describe("given incorrect login", () => {
it("should fail", done => {
nightmare
.goto("https://www.example.com/log-in")
.on("page", (type, message) => {
if (type == "alert") done();
})
.type(".form-control", "RandomPlayer")
.type(".form-control", "XFf13lalfla")
.click(".button")
.wait(20000)
.end()
.then()
.catch(done);
});
});
});
可以使用属性选择器仅选择文本或密码字段 .form控件[name=username]用于用户名, .form控件[name=password]用于输入密码。 用法示例: