Javascript 如何使用nightwatch.js将值设置为textarea属性

Javascript 如何使用nightwatch.js将值设置为textarea属性,javascript,jquery,ui-automation,ui-testing,nightwatch.js,Javascript,Jquery,Ui Automation,Ui Testing,Nightwatch.js,我正在使用nighwatch.js进行web ui测试,我想将值设置为textarea,textarea有一个属性,该属性包含我的实际文本,我正在编写完整的textarea以及下面的设置方式 <div class="textarea-description"> <textarea cols="50" class="myClass setText" data-def placeholder="text to be replaced using nightwatch"/&g

我正在使用nighwatch.js进行web ui测试,我想将值设置为textarea,textarea有一个属性,该属性包含我的实际文本,我正在编写完整的textarea以及下面的设置方式

<div class="textarea-description">
    <textarea cols="50" class="myClass setText" data-def placeholder="text to be replaced using nightwatch"/>
</div>
client.setValue('.textarea-description textarea','new text to be write.');

但是什么都不起作用。

这可能不是最好的解决方案,但它确实有效:

browser
.execute("document.querySelector('.textarea-description .myClass').setAttribute('placeholder', 'nightwatch');")
如果您有jQuery,您可以将它做得更好一些:

browser
.execute("$('.textarea-description .myClass').attr('placeholder', 'nightwatch');")

可以使用xpath获取属性

.useXpath().setValue('//textarea[contains(@placeholder,'text to be replaced using nightwatch')]@placeholder', 'nightwatch')

感谢您提出的所有有价值的建议,您提供的所有建议都能提供很好的知识,但不幸的是,这些建议都不起作用。我已经用下面的方法解决了这个问题

<div class="textarea-description">
    <textarea cols="50" class="myClass setText" data-def placeholder="text to be replaced using nightwatch"/>
</div>
client.setValue('.textarea-description textarea','new text to be write.');
实际上,属性“data def placeholder”只使用了非实际文本的水印,所以它起作用了。

这对我来说很有效

.assert.visible('div.textarea-description textarea.setText')
.moveToElement('div.textarea-description textarea.setText', null, null)
.mouseButtonClick('left')
.keys([browser.Keys.CONTROL, "a"])
.keys([browser.Keys.CONTROL, "nightwatch"])

您是否同时尝试了JavaScript和jQuery?不,我只尝试了第一个,我将尝试第二个,并让您知道。您的textarea没有结束标记(请参阅我对您的问题所做的编辑),我认为这可能也是一个问题。然后我误解了您的问题。这不是关于设置属性,而是在textarea中设置直接值?