0

How to use execute javascript keyword in robot framework to enter text into the textbox.

I have tried to locate element by:

${get_code}  Execute Javascript  document.getElementById('code')

Now I'm trying to input a value into the above element.

4
  • Why are you trying to input text using javascript? There is Input Text keyword in SeleniumLibrary Commented Aug 7, 2018 at 7:35
  • The text box should accept only 20 characters when the user enters 21st character it should throw error message. So when i used input text keyword the text box doesn't throw any error message so trying to use execute javascript keyword Commented Aug 7, 2018 at 8:37
  • Probably you could do it setting value of the element. In your case Execute Javascript document.getElementById('code').value = '${text_variable}' Commented Aug 7, 2018 at 8:45
  • Thanks a lot i have succeeded in passing the input into text field using Execute Javascript document.getElementById('code').value = '${text_variable}' But still the error message is not displayed so i have used 'Press Key' events for 21 consecutive times. Now the error message is dispayed, So the issue was the text is waiting for the key press event to throw the error message. Commented Aug 7, 2018 at 9:04

1 Answer 1

0

Simply enter your script as argument to your keyword. In your case something like this:

Execute Javascript    document.getElementById('code').value="Your Text"

See documentation or this answer for additional info.

UPDATE on comment

Kindly suggest a way to iterate the "Press Key" keyword using for loop to make it look simpler

[Documentation]  Loops over values from 97 to 118
:FOR    ${ascii_code}    IN RANGE    97    119
    \    Press Key   ${code}    \\${ascii_code}
Sign up to request clarification or add additional context in comments.

1 Comment

Error message is thrown only on using "Press Key" event, Kindly suggest a way to iterate the "Press Key" keyword using for loop to make it look simpler Instead of having 20 lines of Press Key ${code} \\097, Press Key ${code} \\098 and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.