3

I am working on nighwatch.js for web ui testing, I want to set value to a textarea, and textarea has an attribute which has my actual text, I am writing full textarea and how I am setting in following.

<div class="textarea-description">
    <textarea cols="50" class="myClass setText" data-def placeholder="text to be replaced using nightwatch"/>
</div>

I am trying to set value in above textarea's attribute data-def placeholder as following ways

browser.setValue('.textarea-description textarea[type=text]','nightwatch'); or
browser.setValue('.textarea-description textarea[data-def placeholder=text]','nightwatch'); or
browser.setValue('.textarea-description textarea[type=data-def placeholder]','nightwatch');

but nothing is working.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Ashish-BeJovial
  • 1,829
  • 3
  • 38
  • 62

4 Answers4

1

This might not be the best solution but it works:

browser
.execute("document.querySelector('.textarea-description .myClass').setAttribute('placeholder', 'nightwatch');")

If you have jQuery you can make it a bit nicer:

browser
.execute("$('.textarea-description .myClass').attr('placeholder', 'nightwatch');")
Fredrik Schöld
  • 1,588
  • 13
  • 20
1

Thank you for your all valuable suggestions, all suggestions provided by you was able to give good knowledge but unfortunately none of the suggestion worked. I have resolved it by using following.

client.setValue('.textarea-description textarea','new text to be write.');

Actually attribute "data-def placeholder" was using only watermark that was not actual text, so it is working.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Ashish-BeJovial
  • 1,829
  • 3
  • 38
  • 62
  • 1
    Then I misunderstood your question. It wasn't about setting the attribute but rather setting the direct value in the textarea? – Fredrik Schöld Feb 01 '16 at 07:57
0

You could use xpath to get the attribute.

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

How to select specified node within Xpath node sets by index with Selenium?

Community
  • 1
  • 1
QualiT
  • 1,934
  • 2
  • 18
  • 37
0

This worked for me.

.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"])
Anil Maharjan
  • 703
  • 1
  • 6
  • 9