Daniel Rusu
Daniel Rusu

Reputation: 113

Selenium Auto Submits Form with Send_keys?

I'm using Selenium 2.53 with python 3.4 and firefox 47 to do automation testing. When using .send_keys (sendKeys in Java) it will auto submit the form when I dont want it to.

The form input that I'm sending keys to is:

<input tabindex="1" type="text"
                    name="PostingTitle"
                    id="PostingTitle"
                    maxlength="70"
            </label>

It's strange because it doesnt do this with all the forms. Is there a way to tell selenium not to submit?

Upvotes: 2

Views: 1502

Answers (1)

Saurabh Gaur
Saurabh Gaur

Reputation: 23805

When using .send_keys (sendKeys in Java) it will auto submit the form when I dont want it to.

It might be possible your desired text box is capturing key events during sendKeys which may be call any JavaScript function to submit the form, because sendKeys working normally as user input from keys.

From comments :-

No new line and no 'enter' or 'return' or related keys. No event occuring during sendKeys on the html.

Then it's hard to say why sendKeys submit your form.

You can use execute_script() instead which would silently set the value into your textbox without occuring any events as :-

driver.execute_script("arguments[0].value = arguments[1]", driver.find_element_by_id("PostingTitle"), "you‌​r value to set")

Upvotes: 1

Related Questions