Herawati Manurung
Herawati Manurung

Reputation: 5

How to typetext in textarea which have dynamic element?

I want to input text in textarea, but unable to find the element since the id is dynamic, and if I use class, element is visible. Here's Snippet Code of the element, here's the UI. I wrote this on my script

let textArea = Selector('.block-card list-group-item text-card col-xs-12').find('textarea')
await t
    .typeText(textArea, 'Hai...')

I got error:

The specified selector does not match any element in the DOM tree.

> | Selector('.block-card list-group-item text-card col-xs-12')
  |   .find('textarea')

I also use

let textArea = Selector('.hwt-container').find('textarea').withAttribute('class','text-card-text')

Still the same.

Upvotes: 0

Views: 616

Answers (1)

Alex Skorkin
Alex Skorkin

Reputation: 4274

Try using the hasClass method instead of withAttribute.

UPDATE:

Here's my sample test case:

60986279.html

<div id="cardList" class="list-group">
<div id="1585" class="block-card list-group-item text card col-xs-12">
<div class="hwt-container">
<div class="hwt-backgdrop">
<textarea id="1585" maxlength="640" spellcheck="false" placeholder="Enter Text" style="overflow: hidden; break-word;" class="text-card-text maxlengthBadge form-control"></textarea>
</div>
</div>
</div>
</div>

60986279.js

import { Selector} from 'testcafe';

fixture('fixture')
    .page('file:///path/60986279.html');

test('test', async t => {
    let textArea = Selector('.block-card').find('textarea')
    await t.typeText(textArea, 'Hai...')
});

Upvotes: 1

Related Questions