Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

See attached. Once in awhile (say, one in several hundred test runs), I'll have something like this happen:

incorrect send_keys typing

What it should have typed was AttachmentCount:0.

Another example where it is retyping "very" and this time with the wrong case:

enter image description here

I have also seen it happen where it stops typing in the middle of a send_keys() phrase I'm sending (see example screenshot in a comment below).

The function I'm using is below. I'm using Selenium 2.23 on Windows 7 with Firefox 13. Any ideas on why this happens? I can re-run the test and it'll be fine. I have 113 other searches in this test that typed out fine.

def do_find(self, term):
    """ interacts with the search form """
    textbox = self.browser.find_element_by_id('query')
    textbox.clear()  # for when we loop and search more than once
    tab = util.webdriver.common.keys.Keys.TAB
    textbox.send_keys(term, tab)  # tab closes autocomplete popup
    findb = self.browser.find_element_by_id('findbutton')
    findb.click()
share|improve this question
1  
Are you doing other things on the machine at the same time or are the tests running on a dedicated machine? If running on a dedicated machine is there a chance that another window or dialog box could be popping up and momentarily taking over as the foreground window? –  Sam Woods Aug 8 '12 at 20:29
    
Sam, that's a good thought, but unfortunately it isn't possible. I have it running inside a dedicated VM, and kick off my Python test manager + nose + Selenium framework from Scheduled Tasks, so there's literally only the Firefox windows open. I guess it's possible that it's a Windows Update popup? But those only show in the tray; I don't think they steal focus. –  Aaron Aug 9 '12 at 21:13
    
I haven't seen this before, but there are only a handful of places where the automation I'm working on enters text into a textbox so the likelyhood would be a lot less. The OS and Firefox version are the same, only difference is I'm still on Selenium 2.21. It is interesting that it is repeating itself, I'm not sure what the selenium retry logic looks like inside of sendkeys but it's possible that there is a bug there where it believes there is an error so tries to resend... When it fails, does it happen setting the text of same textbox every time, or a random textbox? –  Sam Woods Aug 9 '12 at 21:21
    
It's always that same textbox. There is auto-complete in that box, but it should only be popping up when there's a pause in typing, which there isn't for send_keys. And it's odd that the other 113 searches are fine. If it were autocomplete interfering, I'd expect it to happen a lot more. –  Aaron Aug 10 '12 at 22:21
1  
That really seems to me like the window is momentarily losing focus somehow... I can't think of another reason this would happen. –  Sam Woods Aug 15 '12 at 22:22
show 1 more comment

3 Answers

Interesting. I'd probably create a test that just navigates to the page and enters text into that texbox and repeat it a hundred times then watch the execution and see if I can catch it in the act to see what might be going on. It could be something to do with auto-complete, especially if that took focus away from the textbox. That could cause selenium to switch focus back to the textbox and retry.

share|improve this answer
    
Sam, that's a good idea. I will put that on my to do list. Do you know if there's some kind of debug logging I could enable to get more info when it happens? –  Aaron Aug 14 '12 at 17:06
add comment
up vote 1 down vote accepted

Well, this is more of a workaround than a true fix or answer -- and I'll award the bounty to any better solution -- but here's what I ended up doing. It checks to make sure it typed what I wanted it to type, and retries if not.

def do_find(self, term):
""" interacts with the search form """
for _ in xrange(5):
    textbox = self.browser.find_element_by_id('query')
    textbox.clear()  # for when we loop and search more than once
    textbox.send_keys(term)
    close_ac = self.browser.find_element_by_class_name('project_name')
    close_ac.click()  # close autocomplete so WebDriver can see Find button
    elem = self.browser.find_element_by_id('query')
    actual_text = elem.get_attribute('value')
    if actual_text == term:
        findb = self.browser.find_element_by_id('findbutton')
        findb.click()
        break
    else:
        pass  # retry because of rare send_keys() problem
share|improve this answer
add comment

I found the same error and couldn't isolate it either. I basically wrote a wrapper for the sendkeys function which would check that the value entered was correct or would retry for 2 seconds. My code is in java but it would be easy to write it in another language. I see you have basically done the same thing though.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.