问题
I'm trying to do nightwatch and cucumber integration for BDD. I'm unable to access client.elements function in a step function.
const { client } = require('nightwatch-api');
const { Given, Then, When } = require('cucumber');
const homePage = client.page.homepage();
Then(/^click "([^"]*)" service from list$/, async(service) => {
let result = await client.url('http://localhost:8080/').elements('css selector', 'div.flex.mt-4.v-card.v-sheet.theme--light > div > div > table > tbody > tr');
console.log(" col length is " + "<->" + result.value.length);
return homePage;
});
Any help is appreciated. thanks!
回答1:
I tried to replicate this and below is working for me.
await client.url('https://www.phptravels.net/home').moveToElement('css selector', '.product-grid-item', 0, 0).elements('css selector', '.product-grid-item', (res) => {
console.log("%%%%%%% col length is " + "<-> " + res.value.length);
});
I am not sure if we can store the response returned from elements api in a variable. I will update this answer if I find a way to do that.
来源:https://stackoverflow.com/questions/60459467/client-elements-is-not-working-from-a-step-definition-using-nightwatch-api