Iterating elements using NightWatchJS

本文介绍了使用Nightwatch.js及jQuery进行DOM元素遍历的方法,包括通过execute执行应用上下文函数、利用querySelectorAll获取元素并迭代操作,以及结合Nightwatch.js API实现元素点击等交互。

1) used the following strategy to iterate over DOM elements using Nightwatch:

// Executing a function in the application context.
client.execute(function () {

  // Get elements by CSS selector.
  var elements = document.querySelectorAll('.elements');

  // Iterate over them.
  [].forEach.call(elements, function (element) {

    // Manipulate each element.
    element.click();
  });
});

  

2) the number returned by allitems.value[0].ELEMENT will work as the id.

 

3) jQuery 定位

$('#padt_lic_numb > ul > li > label').each(function(){

                $(this).click();
                      
         });

4) nightwatchjs

client.elements("css selector","#padt_lic_numb > ul > li > label",function(results)
{
  results.value.forEach(function(index){
  // console.log('Element value is '+index.ELEMENT);
  client.elementIdText(index.ELEMENT,function(result){
  //console.log(result.value);
  if(result.value == plate_number)
  {
    console.log(result.value);
    console.log(plate_number);
    client.elementIdClick(index.ELEMENT);
  }
  });
  })

});

  

转载于:https://www.cnblogs.com/saryli/p/8384305.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值