Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To send threekeys using send_keys() in selenium python webdriver

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

like image 245
senthil3569 Avatar asked Jan 10 '12 06:01

senthil3569


2 Answers

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.

like image 175
Glenn Avatar answered Sep 23 '22 21:09

Glenn


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'
like image 30
Misha Akovantsev Avatar answered Sep 21 '22 21:09

Misha Akovantsev