Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium not setting input field value

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?

like image 582
CracLock Avatar asked Feb 05 '15 14:02

CracLock


People also ask

How to set value to text box in selenium?

We can set value in Textbox by using the sendKeys() method. We can locate the Textbox elements by id, name, CSS, and XPath selector.

How do I edit text box in selenium?

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.


1 Answers

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')
like image 145
alecxe Avatar answered Oct 20 '22 02:10

alecxe