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?
We can set value in Textbox by using the sendKeys() method. We can locate the Textbox elements by id, name, CSS, and XPath selector.
Selenium can be used to input text to an edit box. An edit box is represented by the input tag and its type attribute should have the value as text. It can be identified with any of the locators like - id, class, name, css, xpath and tagname. To input a value into an edit box, we have to use the method send_keys.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With