1

On the page I want to test I have a form like this:

<form method="post" action="target.html">
    <input id="myInputField" />
</form>

A normal use-case here would be that the user enters some text and then hits enter. For testing I tried sending the Special-Key "enter" but that results in an exception:

org.openqa.selenium.WebDriverException: Cannot locate element used to submit form

Is there a way to submit a form without having a button present? I am testing headless with HtmlUnitDriver.

fuzzi
  • 87
  • 8

2 Answers2

0

With a little workaround I got it to work: Creating the submit button but setting the display to none does the trick. But I am still searching for a better solution

<form ...>
...
<input type="submit" style="display:none" />
...
</form>

Now the send()-Method can find the submit-Element.

fuzzi
  • 87
  • 8
0

Have you also tried

.sendKeys(Keys.RETURN)

instead of .ENTER?

If this doesn't work I think the answer of @fuzzi is the best way or take a look at this!

M.K
  • 25
  • 1
  • 2
  • 8
  • I just did, but it's the same result: ```Cannot locate element used to submit form``` – fuzzi Aug 12 '20 at 14:53
  • Then you're simply missing a `` which would enable entering the values without a button. – M.K Aug 12 '20 at 15:01
  • That is exactly what I did in the answer I posted below. But in my opinion it is just a workaround and should work without. Or maybe it is just not possible with selenium. – fuzzi Aug 13 '20 at 18:48