Enter a long multi-line text

Question

How can i add multi-line texts in a multi line text field present in my website?

I tried using the set text (that empties the field if something is present there) but if i try to paste the text, only the first line is shown.

in progress 0
Execution 14 Answer 384 views

About the Author

Answers ( 14 )

  1. This comment is edited.

    Hello, try to add a line separators into a single setText method.
    WebUI.setText(testObject, "first line\nsecondline\nthird line")

    • The thing is, that this website will have text fields that will have up to 600.000 characters (that’s the max i’ve seen so far) but mostly between 100’s and 1000’s, many of them having multiple lines. It would be nonsense for me to put a separator between every new line ( i want to use real data, not copy pasting 1000 words with separators between them)

  2. Marek Melocik: We will have to enter predefined texts, always different, but for testing purposes i will use a longer general text.

    @duyluong Sorry i don’t understand what are you saying.

    When i try to add a Value to the Set text, and paste the text that has new lines (enter) then only the first line get’s pasted in that field. As i am typing this i realized that the text is with \n in the dev (f12) response! i will try that, thanks.

     

     

  3. Hi there,

    Based on duyluong answer, please your multiple lines of text into the variable using triple single quoted, then use it, e.g
    def yourText = '''
    line one
    line two
    line three
    ....
    line n
    '''

    WebUI.setText(findTestObject(”), yourText)

    Thanks

  4. Do you have a sample text so that I can try and give you the screenshot?

    Thanks

    • This comment is edited.

      Let’s do it with the classic: http://www.lipsum.com/feed/html – (i think this comment section changes it a bit)

      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin congue tempus tempor. Donec pretium viverra eleifend.

      Aliquam et condimentum sem. Sed molestie nisl lectus, eget ultrices lorem tincidunt in. Morbi sed hendrerit dolor. Aliquam erat volutpat.

      Integer maximus ex tempus auctor elementum. Vivamus vel lacus eu ante maximus consequat. Vestibulum lacus eros, gravida in massa ut, malesuada ultricies quam.

      Suspendisse pharetra eros nec auctor posuere. Nunc sit amet dignissim eros. Suspendisse imperdiet tristique massa, id lacinia orci viverra id.

      Etiam aliquam eros orci, eu malesuada ipsum commodo quis.

       

  5. This comment is edited.

    Ok here is it:
    def yourText = ”’
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin congue tempus tempor. Donec pretium viverra eleifend.
    Aliquam et condimentum sem. Sed molestie nisl lectus, eget ultrices lorem tincidunt in. Morbi sed hendrerit dolor. Aliquam erat volutpat.
    Integer maximus ex tempus auctor elementum. Vivamus vel lacus eu ante maximus consequat. Vestibulum lacus eros, gravida in massa ut, malesuada ultricies quam.
    Suspendisse pharetra eros nec auctor posuere. Nunc sit amet dignissim eros. Suspendisse imperdiet tristique massa, id lacinia orci viverra id.
    Etiam aliquam eros orci, eu malesuada ipsum commodo quis.
    ”’
    WebUI.setText(findTestObject(‘Page_CuraAppointment/txt_Comment’), yourText)
    Here is the screenshot: http://prntscr.com/fgv3t0

  6. Hi,

    Was struggling with the same today to add next lines in a textarea. Ended up creating a custom keyword which changes ‘\n’ from the input string to shift+enter keys too simulate the next line, hope this helps.

    The custom keyword:

    /**
    * Set the text of a textarea, next line with '\n'.
    * @param testObject Katalon test object.
    * @param text Text to add too the textarea.
    */
    @Keyword
    def SetTextArea(TestObject testObject, String text) {
    if(text.contains("\\n")){
    text = text.replace("\\n", Keys.chord(Keys.SHIFT, Keys.ENTER))
    }
    else{
    text = text.replace("\n", Keys.chord(Keys.SHIFT, Keys.ENTER))
    }

    WebUI.sendKeys(testObject, text)
    }

    Details about custom keywords: https://www.katalon.com/resources-center/tutorials/advanced/create-custom-keyword/

Leave an answer