代码之家  ›  专栏  ›  技术社区  ›  Ashish-BeJovial

如何使用nightwatch制作具有共同属性值的相同元素的列表。js还是javascript?

  •  0
  • Ashish-BeJovial  · 技术社区  · 9 年前

    我在夜班工作。js用于web应用程序的自动化测试,我正在努力制作一个元素列表,这些元素的属性中有共同的值,我正在编写如下元素示例。

    前三个跨度具有属性的公共值:“data annotation id”

    <span class="my-note" data-annotation-id="580ss7ze8457f65119v54g32">first span</span>
    <span class="my-note" data-annotation-id="580ss7ze8457f65119v54g32">second span</span>
    <span class="my-note" data-annotation-id="580ss7ze8457f65119v54g32">Third span</span>
    

    上面的span属性(数据注释id)值为: “580ss7ze8457f65119v54g32”

    后两个跨度具有属性的公共值:“dataannotationid”

    <span class="my-note" data-annotation-id="569dd7fe6092b62008b73b49">Fourth span</span>
    <span class="my-note" data-annotation-id="569dd7fe6092b62008b73b49">Fifth span</span>
    

    上面的span属性(数据注释id)值为: “545码6gd8265g7584g5s25”

    我尝试使用以下方法收集所有跨度,这些跨度具有数据注释id属性的公共值,但无法正常工作。

    client.getText('.my-class', function(result) {
       client.expect.element('.my-class').to.have.attribute('data-attr').which.matches(/^something\ else/);
    });
    

    以下语法将不起作用,因为我不知道data-annotation-id的值。所以,有没有任何方法可以使用“守夜人”获得期望的结果呢。js还是javascript?

    client.expect.element('.my-class').to.have.attribute('data-attr').which.matches(/^something\ else/);
    
    1 回复  |  直到 9 年前
        1
  •  0
  •   Ashish-BeJovial    9 年前

    我已经使用了以下代码行。

    //using this line we are getting the number of spans in page.
    client.elements('css selector','.my-class', function (noted) {        
      //on the basis of the number of noted i am finding attribute which has same value.
        noted.value.forEach(function (index) {
           client.getAttribute('.my-class', 'data-annotation-id', function(results) {
             console.log(results.value)
           });
        });         
    });