Input focus changes before sendKeys() operation finishes

521 views
Skip to first unread message

jpi...@live.com.au

unread,
Jan 27, 2016, 10:18:36 PM1/27/16
to Selenium Users
Hi guys,

I have an interesting problem running acceptance tests using TestNG with Selenium Server 2.48.2. The test in question attempts to clear() and then sendKeys(...) to a particular input, and then clear() and sendKeys(...) to another input. The result we see, however, is that the second input receives both of the sendKeys(...) texts.

The inputs are targetted correctly (using By.id), and this issue seems to be transient, but occurs frequently enough to be a problem. Has anybody encountered something similar, or have a theory as to why this would happen? It's almost as if the commands are happening asynchronously and the call to clear() on the second input somehow beats the call to sendKeys(...) on the first. Surely this isn't the case?

Cheers,
Jake.

murali seleniumtrainer

unread,
Jan 28, 2016, 2:23:32 AM1/28/16
to Selenium Users
Hi,

Try with some sleep in between may Thread.sleep(3000) work very well for me like see situation. Use this sleep comment before first input clear and also before second input clear

Thank You,
murali

Mark Collin

unread,
Jan 28, 2016, 3:45:32 AM1/28/16
to Selenium Users
Never use random Thread.sleep() in your code.  You are slowing things down for no good reason and different machines with different amounts of processing power will needs different timeframes.

If you need to wait for something use an explicit wait!

murali seleniumtrainer

unread,
Jan 28, 2016, 5:56:25 AM1/28/16
to Selenium Users
Hi Mark,

I will also accept usage of implicit and explicit waits. But here input boxes are available and no need to wait but due to some reasons may be speed of execution inputs or sendkeys does not work as expected. so Thread.sleep(2000) may helps here...

Thank You,
murali

jpi...@live.com.au

unread,
Jan 28, 2016, 5:14:43 PM1/28/16
to Selenium Users
Thanks for your input guys.

Explicit waits shouldn't be necessary here, as both inputs are ready and available. Thread.sleep() also isn't a solution, because we have a large testing codebase and making this change would not only introduce an unacceptable time lag, but is also far too sweeping.

What we cannot understand is that this problem has only started recently. Has the behaviour of clear() or sendKeys() changed in one of the later Selenium releases? If these commands execute out of order, then that seems like a Selenium bug.

murali seleniumtrainer

unread,
Jan 28, 2016, 8:58:10 PM1/28/16
to Selenium Users
Hi,

Did you tried same in new Jar 2.50

"v2.50.0
=======

WebDriver:
    * Firefox: fixing sendKeys throwing "cross-process JS call failed " in FF45"

Thank You,
Murali
seleniumtrainer.com

On Thursday, January 28, 2016 at 8:48:36 AM UTC+5:30, jpi...@live.com.au wrote:

jpi...@live.com.au

unread,
Feb 2, 2016, 10:03:36 PM2/2/16
to Selenium Users
I've retried after upgrading to the following:

* Selenium v2.50.1
* Chromedriver v2.21
* Chrome v48

Issue remains. Input focus seems to be changing before a call to sendKeys() completes, resulting in some or all of the value being entered into the next input that is targetted.

Mallik H

unread,
Feb 4, 2016, 9:03:15 AM2/4/16
to Selenium Users
Give a try:

1. First input: a) click(), b. clear() and then sendKeys(...)
1. Second input: a) click(), b. clear() and then sendKeys(...)


On Thursday, January 28, 2016 at 8:48:36 AM UTC+5:30, jpi...@live.com.au wrote:

Shashi

unread,
Feb 4, 2016, 10:02:09 AM2/4/16
to Selenium Users
If you haven't already done so, I would suggest running the test in Debug mode with break points after the first "clear" and after the first "sendKeys" (I am hoping your IDE supports breakpoints and debugging).  Step through each and see if the operation successfully completes (field is cleared and then populated with the full string).  Also observe the test as it runs and see if there are any performance issues during the clear and the sendKeys (text typed too slow or too fast - or anything else abnormal).  

Some other questions to answer:
a) Is this issue only on the particular page you are testing or everywhere that you are typing in text?
b) Has something changed in the application - either on the page or in general with the way text is typed into the text fields (depending on the answer to the first question).
c) If you run the test on multiple test servers, does the issue occur on all test servers or just particular ones? 

The above would confirm whether this is a test issue (timing issue or something else) or it may point you in a different direction (perhaps a bug or performance issue due to a recent change in the application?).

Hope that helps,
Shashi

jpi...@live.com.au

unread,
Feb 10, 2016, 6:07:06 PM2/10/16
to Selenium Users
Thanks Mallik and Shashi. I will try your suggestions.

Shashi, to answer your questions:

a. It happens on all pages, not just specific ones
b. The way in which text is entered into the fields hasn't changed in over a year, but we have updated the selenium.jar multiple times during this period
c. Issue occurs on all test servers
Reply all
Reply to author
Forward
0 new messages