client.elements is not working from a step definition using nightwatch-api

▼魔方 西西 提交于 2020-03-25 18:38:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!