Nilovi
Nilovi

Reputation: 15

Selenium IDE sendKeys doesn't trigger the js validation function on number fields

I am trying to test if a validation error shows up when the user types a number into a number field that is not a whole number. The error appears when I type it into the field manually, but when I run it in selenium, the js is never triggered so the error doesn't show on the screen and the test fails.

<tr>
    <td>type</td>
    <td>//*[@id='notificationTimerNum']</td>
    <td></td>
</tr>
<tr>
    <td>sendKeys</td>
    <td>//*[@id='notificationTimerNum']</td>
    <td>1.5</td>
</tr>
<tr>
    <td>waitForVisible</td>
    <td>//*[contains(@class, 'control-error')]//*[contains(., 'The number of minutes must be entered as a whole number')]</td>
    <td></td>

I have also tried using the fireEvent command as suggested here with no luck.

In addition, I am unable to run Selenium IDE sendKeys on my local browser outside of the test environment because it errors out on sendKeys when trying to type a value into the number field.

[error] Unexpected Exception: Error: Cannot set the selection end. 

Upvotes: 1

Views: 1312

Answers (1)

Klendathu
Klendathu

Reputation: 793

I've experienced the same issue, in some cases, you have to send a keypress to the field AFTER you've entered the text, so after your sendKeys command with the number, do another one right after to send either a tab or enter keypress.

sendKeys | //*[id=notificationTimerNum] | ${KEY_TAB} (or ${KEY_ENTER})

For me, that "triggers" the validation of the data in the field, and you can then do the waitForVisible for the error message.

Klendathu

Upvotes: 2

Related Questions