0
votes

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.

1
Why are you trying to input text using javascript? There is Input Text keyword in SeleniumLibraryJaPyR
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 keywordPoovin
Probably you could do it setting value of the element. In your case Execute Javascript document.getElementById('code').value = '${text_variable}'JaPyR
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.Poovin

1 Answers

0
votes

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}