Selenium Webdriver enter multiline text in form without submitting it

后端 未结 3 1604
走了就别回头了
走了就别回头了 2021-01-05 10:57

I have a multiline text and when I am simply putting the whole text into a form using sendKeys, the form gets submitted on each line break.

I tried replacing the ne

3条回答
  •  盖世英雄少女心
    2021-01-05 11:22

    This is not a Selenium issue, pressing enter in a text field often submits the form. Usually you can bypass it by using Shift+Enter to insert a new line. Try this:

    String myText = "first line\nsecond line";
    myText = myText.replace("\n", Keys.chord(Keys.SHIFT, Keys.ENTER));
    myElement.sendKeys(myText);
    

提交回复
热议问题