9

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.

asked Jun 17, 2011 at 21:30
6
  • Is this specific to IE? Commented Jun 18, 2011 at 0:18
  • Is this Selenium 1 or Selenium using Webdriver? Commented Jun 18, 2011 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. Commented Jun 18, 2011 at 7:37
  • It's only IE and it's under Selenium 2 WebDriver. Updated text to reflect that. Commented Jun 20, 2011 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. Commented Jun 20, 2011 at 14:25

3 Answers 3

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. :)

answered Jun 21, 2011 at 10:41
2
driver.ExecuteScript(string.Format("document.getElementById('cred-password-inputtext').value='{0}';",password));

This solution has resolved my problem.

Kate Paulk
31.5k8 gold badges56 silver badges109 bronze badges
answered May 31, 2016 at 18:24
1
  • This is the only thing that worked for me in python/selenium/phantomjs : driver.execute_script("document.getElementById('email').value='test';"); Commented Jun 1, 2016 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.

answered Sep 10, 2015 at 0:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.