14

I am trying to type a float number into a textbox with default value 0.00.But it tries to get appended instead of overwriting it.I tried with .clear() and then send_keys('123.00') but still it gets appended. Then i tried with send_keys(Keys.CONTROL+'a','123.00').It updates 0.00 only.

Any help is really appreciated.

For more info .. URL : http://new.ossmoketest.appspot.com userid: [email protected] -- mycompanyname = orangescape (sorry to avoid spam mails) password not needed now. click purchaseorder... in the form please new product and new price... sample application for automation.. thanks

2
  • Add much more of the actual code into your question Commented Jan 10, 2012 at 6:35
  • 1
    atlast i found the answer... send_keys(Keys.CONTROL+'a'+Keys.NULL, str(newprice)) Commented Jan 12, 2012 at 9:26

4 Answers 4

20

I've had good results with:

from selenium.webdriver.common.keys import Keys

element.send_keys(Keys.CONTROL, 'a')
element.send_keys('123.00')

If that doesn't work it may have something to do with the code in the web page.

Sign up to request clarification or add additional context in comments.

Comments

7

Unless you have custom editbox, click() should work for you:

from selenium.webdriver import Firefox

b = Firefox()
b.get('http://google.com')
e = b.find_element_by_id('lst-ib')

e.click()  # is optional, but makes sure the focus is on editbox.
e.send_keys('12.34')
e.get_attribute('value')
# outputs: u'12.34'

e.click()
e.clear()
e.get_attribute('value')
# outputs: u''

e.send_keys('56.78')
e.get_attribute('value')
# outputs: u'56.78'

Comments

4

I just found the clear() command - see here:

If this element is a text entry element, this will clear the value. Has no effect on other elements. Text entry elements are INPUT and TEXTAREA elements.

EDIT: So your approach would be:

   element.clear();
   element.sendKeys('123.00');

Comments

3

I've experienced issues with all the examples given in other answers.

el.send_keys(Keys.CONTROL + 'a' + Keys.NULL, 'your string')

Has worked in all the projects I've worked in, so much I've wrapped it into my own implementation of the Webdriver class with more robust operations.

Comments

Your Answer

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.