22

Let's say we have this website https://www.coinichiwa.com/ which has a BET AMOUNT input box. It's html is:

<input autocomplete="off" id="betFa" name="a" maxlength="20" value="0.00000000" class="betinput" style="">

I need to add some value into it. Here is my code:

browser = webdriver.Firefox()
browser.get('https://www.coinichiwa.com')

browser.find_element_by_id("betFa").send_keys("0.00000005")
print browser.find_element_by_xpath("//input[contains(@id,'betFa')]").text

But it's neither setting it's value to "0.00000005" nor it printing the value of input.

I'm not sure what's going wrong. Can you suggest? Why it's not working?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
CracLock
  • 653
  • 3
  • 9
  • 27

1 Answers1

32

You need to clear() the text input first:

bet_fa = browser.find_element_by_id("betFa")
bet_fa.clear()
bet_fa.send_keys("0.00000005")

As for the your second problem - this is an input and the value you enter into it is kept inside the value attribute, not the text. Use get_attribute() method:

browser.find_element_by_xpath("//input[contains(@id,'betFa')]").get_attribute('value')
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • 1
    thanks, it worked like charm but one more issue... how do i get `
    0.00100101
    ` the `jukeamt`
    's inside value?
    – CracLock Feb 05 '15 at 14:25
  • 1
    @CracLock okay, If I understood the question correctly: `driver.find_element_by_id('jukeamt').text`. – alecxe Feb 05 '15 at 14:26
  • 1
    ah, not working this way. tried but it's returning empty – CracLock Feb 05 '15 at 14:27
  • 1
    @CracLock well, it is a separate problem, definitely solvable - please consider asking a separate question if you need help and throw me a link here in comments. Thank you for understanding. – alecxe Feb 05 '15 at 14:29