8

We're trying to use Selenium 2.0b3 to verify behavior of a Java web site we've recently acquired from a third party. The site often uses AJAX to plop HTML replacements onto the page.

Internet Explorer, however, findElement of any form input followed by sendKeys only works half the time. For the findElement, we're using a WebDriverWait with an ExpectedCondition returning the element we want, and that returns successfully. Observing the results of the sendKeys on this element, though, we often see nothing appear in the field.

We have no problems filling out login forms that are initially loaded when the HTML page initially loads; these problems seem to entirely occur on anything that's just been loaded with an innerHTML change through an asynchronous request. (We also, perhaps unsurprisingly, don't have these problems with Firefox.)

Adding arbitrary time delays after the page transition but before doing the findElement doesn't appear to help. (I tried waiting for 10 seconds after we saw the async request finish setting innerHTML and the problem still occurred occasionally.)

Any idea what this might be, or how to work around it?

EDIT: Just to be clear, this is happening under IE with Selenium 2 WebDriver.

  • Is this specific to IE? – user246 Jun 18 '11 at 0:18
  • Is this Selenium 1 or Selenium using Webdriver? – sean_robbins Jun 18 '11 at 7:31
  • Sounds similar to a problem I dealt with recently using watir-webdriver (which, if you're using webdriver will be similar). In my case I was able to resolve/ workaround by sending a click at the element (to select it) before using sendKeys. – sean_robbins Jun 18 '11 at 7:37
  • It's only IE and it's under Selenium 2 WebDriver. Updated text to reflect that. – Alan Krueger Jun 20 '11 at 13:36
  • @sean_robbins Your suggestion appears to work. If you could promote that to an answer, I'll mark it as the correct one. – Alan Krueger Jun 20 '11 at 14:25
7

This sounds similar to a problem I dealt with recently using watir-webdriver (which, if you're using webdriver will be similar). In my case I was able to resolve/ workaround by sending a click at the element (to select it) before using sendKeys. So I suggest you could try sending a click to the element before using sendKeys. :)

2
driver.ExecuteScript(string.Format("document.getElementById('cred-password-inputtext').value='{0}';",password));

This solution has resolved my problem.

  • This is the only thing that worked for me in python/selenium/phantomjs : driver.execute_script("document.getElementById('email').value='test';"); – wbt11a Jun 1 '16 at 14:24
0

You can try using the following command:

send_keys(driver.find_element_by_css_selector('#select_something'), value)

Furthermore, you need to redefine send_keys as:

def send_keys(element, keys): for key in keys: element.send_keys(key)

Sending keys one by one is more reliable and less buggy. Syntax is in python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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