如何使用 mouseButtonDown() 函数通过 nightwatch.js select 元素的文本?

How to select text of an element by nightwatch.js using mouseButtonDown() function?

我正在使用 nightwatch.js 进行自动化测试,我对这项测试工作很陌生,我想执行元素的文本选择,因此我可以使其突出显示或注释所选文本。

我正在使用 mouseButtonDown(0) 和 mouseButtonUp(0) 函数来选择文本,但它没有选择,我的代码如下。

'Make highlights by Dragging mouse' : function (client) {
  var bookView = client.page.book();
  bookView.loadBook();
  client.pause(3000);
  client.expect.element('.myDivClassId span:nth-child(1)').to.be.present;
  client.getLocation('.myDivClassId span:nth-child(1)', function(location) {
    client.moveToElement('.myDivClassId span:nth-child(1)', location.value.x, location.value.y);
    client.mouseButtonDown(0);
    console.log(location.value.x);
    console.log(location.value.y);
    var xValue = location.value.x;
    xValue = xValue + 200;
    console.log(xValue);
    client.moveToElement('.myDivClassId span:nth-child(1)', xValue, location.value.y);
    client.mouseButtonUp(0);
    client.pause(8000);
  });
  client.waitForElementVisible('.PopUp.Highlight', 5000);
  client.waitForElementVisible('.anchorLink a:nth-child(1)', 5000, function () {
    client.pause(1000);
    client.click('.anchorLink a:nth-child(1)');
    client.pause(10000);  
  });
}

我已经使用回调测试了 mouseButtonDown() 函数,它工作正常我得到状态 0,它的意思是 mouseButtonDown() 正在工作但文本没有选择。有没有其他方法可以测试 mouseButtonDown() 和 mouseButtonUp 函数?

我找到了答案,我用一个例子来说明事情。

Example: <input id="gotopage" placeholder="4" data-page="4" data-totalpages="84" data-tabindex="12" tabindex="12">

现在使用 nightwatch 函数 'getAttribute' 获取输入 属性 占位符的值,如下所示。

client.getAttribute('.page_of #gotopageform input#gotopage', 'placeholder', function(receivedValue) {
   this.assert.equal(receivedValue.value, 4);
});

现在阅读问题,使用 mouseButtonDown(0),因此使用 mouseButtonDown() 无法进行任何选择,在这种情况下您可以做什么,使用 moveToElement() 函数然后使用 getAttribute() 然后使用 mouseButtonDown() 函数, 所以这将是获取此问题所需结果的方式。

完成!!! :)