问题描述
比方说,我们有这个网站 https://www.coinichiwa.com/,该网站的投注金额输入框.它的html是:
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
但是既没有将其值设置为"0.00000005",也没有打印输入的value
.
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?
推荐答案
您需要 clear()
首先输入文本:
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")
关于第二个问题-这是一个input
,您输入的值将保留在value
属性中,而不是文本中.使用 get_attribute()
方法:
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')
这篇关于硒未设置输入字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!