Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Nothing happens when I try to fill an jQuery Masked Input with Sel 2.5 #2377

Closed
lukeis opened this issue Mar 3, 2016 · 9 comments
Closed

Comments

@lukeis
Copy link
Member

lukeis commented Mar 3, 2016

Originally reported on Google Code with ID 2377

When I try to execute a simple sendKeys in a field that have a mask create by jQuery
Masked Input nothing happens.

What steps will reproduce the problem?
1. Go to page http://digitalbush.com/projects/masked-input-plugin/
2. Click at Demo tab
3. Try to fill the date field by driver.findElement(By.id("date")).sendKeys("01012011");

What is the expected output? What do you see instead?
The expected result is the field date filled with "01/01/2011"

Selenium version: 2.5
OS: Win 7 x64 and Mac 10.7.1
Browser: Firefox
Browser version: 5 and 6

Another information is that no problem occurs if I use Sel 2.4 libs, it just happens
in 2.5 libs.

Alternatively I used the following code as a workarround in Sel 2.5:
((JavascriptExecutor)driver).executeScript("$('#date').unmask()");      driver.findElement(By.id("date")).sendKeys("01012011");
((JavascriptExecutor) driver).executeScript("$('#date').mask('99/99/9999')");

Reported by elias.nogueira on 2011-08-31 02:21:26

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

There's a little behavior oin this issue, and I don't know why it happens =/

If I try to run the code below the input will not be filled:
---
driver.get("http://digitalbush.com/projects/masked-input-plugin/");
driver.findElement(By.xpath("//div[@id='tabs']/ul/li[2]/a/span")).click();
driver.findElement(By.id("date")).sendKeys("01012011");
---

Btw, if I put a command before sendKeys the test runs and fill the input field:
---
driver.get("http://digitalbush.com/projects/masked-input-plugin/");
driver.findElement(By.xpath("//div[@id='tabs']/ul/li[2]/a/span")).click();
System.out.println("");
driver.findElement(By.id("date")).sendKeys("01012011");
---

It just happens with Sel 2.5

Reported by elias.nogueira on 2011-08-31 21:55:46

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Bisect shows it is caused by r13446.

A workaround is to do element.click() before element.sendKeys

Reported by barancev on 2011-09-01 20:39:18

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

The setCursorPosition call was added in r13404, my change in r13446 merely expanded
it to also include text fields (which had failing tests) as well as textareas and take
into account if the field was already focused.

We should figure out why focusing text fields on FF6 failed in the first place - r13404
is a sloppy workaround (as this issue demonstrates).

Reported by jari.bakken on 2011-09-02 06:48:54

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Ok, element.focus() in Firefox 6 places the cursor at the beginning of the element,
which breaks the contract of sendKeys() if the element is not focused but has some
existing value.

The solution is probably to click the element on the far right side instead of focusing
it in JS.

Reported by jari.bakken on 2011-09-02 11:07:30

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by jari.bakken on 2011-09-02 11:07:39

  • Labels added: Component-WebDriver, Browser-Firefox

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

We can't do anything about this issue :(

Currently, sendKeys tries to *append* typed text to the existing text of a field. That
is, it puts cursor to the end of the field before typing.

With the masked fields from this sample it is wrong strategy -- the cursor should be
put at the beginning of the field.

We can't change the current behaviour, because it will cause *prepending* typed text
to the existing text for regular fields.

Fortunately, it is not impossible to deal with the masked fields -- just 'click' at
the field before typing, when you click it, jquery puts cursor to the correct position
and sendKeys successfully enters data to the field.

Reported by barancev on 2012-06-02 17:59:19

  • Status changed: WontFix

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

"Fortunately, it is not impossible to deal with the masked fields -- just 'click' at
the field before typing, when you click it, jquery puts cursor to the correct position
and sendKeys successfully enters data to the field."

Thanks a lot !!!

Reported by thiago@rosanetur.com on 2013-04-12 03:49:06

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by jari.bakken on 2015-02-26 23:01:20

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by luke.semerau on 2015-09-17 18:13:37

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 3, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant