selenium not setting input field value

2019-04-05 19:35发布

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?

1条回答
我命由我不由天
2楼-- · 2019-04-05 19:52

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')
查看更多
登录 后发表回答