Radim Bukovský
Radim Bukovský

Reputation: 357

Karate - input field/textarea clear field is not working properly

Using Karate I am not able to clear field (input, textarea) properly:

<input name="title" id="title" class="form-control" placeholder="e.g. My MacBook Key" value="">

1) insert to input field with id=title is OK.

retry().input('#title', 'something')

Everything is written to field. OK.

2) I need to clear the field. I use following:

retry().clear('#title')

Field seems to be deleted after this action (text in input field is not visible).

3) But when I use input again

retry().input('#title', 'new')

In field is displayed: somethingnew. It seems that first string was not properly deleted and strings are merged together. It happens for input/text area fields.

Could you help me please? Any idea?

Thank you.

Upvotes: 2

Views: 2693

Answers (2)

Sahana Kattimani
Sahana Kattimani

Reputation: 21

First we need to focus on the web element

  • focus(webElement)

Then clear the input field/text area on the browser, use clear()

  • clear(webElement)

To clear the value from DOM, we are using Key.CLEAR

  • input(webElement, Key.CLEAR)

Finally insert your value/custom value into the input field as below

  • input(webElement, "Insert your value")

Upvotes: 2

Peter Thomas
Peter Thomas

Reputation: 58068

Try using value() or JS directly instead of clear():

* value('#title', '')

Or:

* script('#title', "_.value = ''")

Upvotes: 3

Related Questions