selenium not setting input field value

淺唱寂寞╮ 提交于 2020-01-01 08:06:08

问题


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:


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')


来源:https://stackoverflow.com/questions/28346240/selenium-not-setting-input-field-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!