Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendKeys in InternetExplorerDriver doesn't always send keys #805

Closed
outofrange opened this issue Jul 17, 2015 · 17 comments
Closed

sendKeys in InternetExplorerDriver doesn't always send keys #805

outofrange opened this issue Jul 17, 2015 · 17 comments
Labels

Comments

@outofrange
Copy link

We stumbled over the seldom occuring issue that InternetExplorerDriver won't enter some text into text fields, leaving them blank.

To reproduce and isolate the problem, I've created a small Selenium/Java script that simply enters increasing numbers into a text field and asserts the value of the HTML tag, for 30 minutes.
After a few seconds or minutes, the text field stays empty and the assertion fails; my expectation is, of course, that sendKeys will send keys on every invocation, or at least throws an exception if there is a problem.
Most of the time, we are able to reproduce the problem with this method before we reach 300 - the longest we had to wait was until 839.

In this case, I'm reading the value of the input field immediately after calling sendKeys, but even when looking at the browser after the assertion, the characters won't appear, so I don't believe it's a timing issue.

Both Selenium and IEDriver are at version 2.45.0, and we could reproduce it on a machine with Win7 + IE8, and on another one with Win7 + IE11, although it's rarer on IE11 (meaning it takes longer until it happens)
Windows is 64bit, IE and IEDriver are 32bit.
We are using Java 1.8.0_51 (x64)

It seems that requireWindowFocus = true is relevant.

Since I haven't found anything about this problem on the internet, are we the only ones having these troubles?

@barancev barancev added the D-IE label Sep 20, 2015
@justintilson
Copy link

I'm experiencing the same problem with Firefox 41.0.2 on Mac 10.10.5. I've tried Selenium versions 2.47.1 and 2.48.2. java version: 1.8.0_40

I'm testing a complex inventory form with dynamically generated form elements. More often than not, at least one field is left blank after calling sendKeys() with a new value. The failures are random. Once in a while it will work but generally not. I've tired a variety of wait strategies to make sure the dynamically generated elements are visible and clickable without success

Running the same tests with PhantomJS works fine.

@ckorakidis
Copy link

ckorakidis commented Apr 18, 2016

I'm experiencing the same issue with java version v. 2.53.0 on IE.
In some cases the field will be left empty, in some other cases not all the characters will be written in the field.
I didn't ever have this issue while debugging.
It looks like it's going to fast through these steps as it was mentioned also in this comment

Adding some Thread.sleep() with minimum value 500ms seems to make the webdriver happy. I didn't manage to reproduce it when using that approach while it was easy to reproduce it when the Thread.sleep() was removed. When I was reducing the value from 500 to 400,300,100ms I had the same issues.

@gregoryduckworth
Copy link

Currently I am are running into this issue at the BBC as well, where letters can be dropped from a string when calling sendKeys(). It is being reproduced 2/3 times both locally and on BrowserStack. During testing as well changing the requireWindowFocus=true made no difference.

Local Environment:
IEDriverServer.exe (32 bit)
Windows 7 64 bit
Java 1.8.0_92-b14

@DanielHirst
Copy link

I'm also getting issues where the case is changed. I'm using sendKeys("Test") and every so often it is typing "test" instead. This only happens with IE11, Chrome and Firefox (and even IE10) are all fine.

Is there any appetite to fix this? It basically renders our IE11 tests useless as they're so flaky.

@nickk75
Copy link

nickk75 commented Feb 21, 2017

I'm currently having that issue in Chrome with selenium chrome driver 2.55. I've a modal and once that's closed I move to an input field where I send values and often enough those values won't be sent, and the field will be left empty. Is there a way we can account for that???

@beluha
Copy link

beluha commented Jan 17, 2018

Hello, Selenium 3.7.1 and Selenium 3.8.1 enters random set of characters from provided input text into textarea using sendKeys in java. For example I have textarea web element:

<textarea name="message" rows="10" cols="30">The cat was playing in the garden.</textarea>

When I call sendKeys with text "Selenium automates browsers. That's it! What you do with that power is entirely up to you." web driver first time enters "Selenium automates browsers. That", next time "Selenium automates browsers. That's it". Each time entered text is not complete.

Selenium 3.7.1, 3.8.1
IE 11
IEDriverServer 3.7.0.1, 3.8
Windows 7 64-bit

@houqingchun
Copy link

I encountered the same issue too, issue observed on both IE(driver v2.53) and Chrome(driver v2.34) with selenium 3.33 (windows 2012 server)
The issue was often gone after second round running. It is intermittent, cannot reproduce permanently.
Is there any workaround for this issue?

@walliski
Copy link

walliski commented Jun 5, 2018

I am also seeing that IE11 is missing keys in input, not consistent with being first or last, but random keys in the middle of the input. IEDriverServer 3.12. For chrome it works well though.

@barancev
Copy link
Member

Yes, I've reproduced this issue.

InternetExplorerOptions options = new InternetExplorerOptions().requireWindowFocus();
WebDriver driver = new InternetExplorerDriver(options);
driver.get("http://localhost/addressbook/");
WebElement input = driver.findElement(By.name("user"));
for (int i = 0; i < 1000; i++) {
    input.clear();
    input.sendKeys("test" + i);
    Thread.sleep(500);
    assertEquals(input.getAttribute("value"), "test" +  i);
}

Attaching the part of the TRACE level log that corresponds to the failed iteration.
iedriver.log

requireWindowFocus is important, there is no failure if this option is not specified (at least it passed 1000 iterations).

@jimevans
Copy link
Member

There is no way for the IE driver to fix this problem. None. Full stop. In this case, the driver is using the Windows SendInput API to simulate keystrokes. This API inserts the keystrokes directly into the hardware input queue for the keyboard, so there is no discernible difference from an application's point of view from those keystrokes being simulated by SendInput or actually from the user's keyboard.

After calling SendInput, the driver waits to see if the expected number of keyboard events have been fired. In the instance where the sendKeys fails, the browser is not processing the keystrokes fully. If IE isn't processing the keyboard input properly, there's nothing the driver can do about it.

Folks are welcome to inspect and audit the code to validate that the IE driver is using it correctly, and that it's properly waiting on the processing of events.

@jimevans
Copy link
Member

I have a potential fix that allows the supplied test to run for at least 1000 iterations with requireWindowFocus turned on. It introduces a potential destabilization of the driver behavior because input events can potentially be inserted into an input stream as created by sendKeys. This is the trade-off we'll have to live with, instability in IE not being able to process all of the events correctly, or instability in the potential for other input events interfering by inserting unwanted events into the event stream.

@akashishu777
Copy link

akashishu777 commented Jun 21, 2018

@jimevans I am using selenium 2.53.0 with IE version 11.461, this cause same send key problem as mentioned in this issues does it have any solution? Does selenium version 3.12.1 have any fix of this issue?

@jimevans
Copy link
Member

jimevans commented Jun 21, 2018

IEDriverServer.exe 3.12.0.4 (not released publicly yet, but [checked into the project source tree prebuilts directory and available there) has this change that may help with the issue. Note however that you must use 3.5 or higher of the Selenium language bindings to work with that version of the IE driver.

@kpriyadharsini
Copy link

@jimevans I am using selenium 3.6.0 with IE 11 and driver 3.12.0 . The send_keys issue seems to be fixed. With requireWindowFocus turned on, still I could see click issue in link elements

@jimevans
Copy link
Member

After reports of keystroke issues being fixed, I’m closing this issue. Other issues not with sendKeys should raise a new issue report.

@akgupta0304
Copy link

requireWindowFocus works only when the browser is open. But if the browser is in the minimized state it won't work. How it would work in the minimize state as well?

@jimevans
Copy link
Member

jimevans commented Oct 3, 2018

@akgupta0304 The IE driver does not allow interaction with elements when the window is minimized. This is a limitation of the driver, and is unlikely to change.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests