How do you get input value if value already exists as an attribute in Selenium?
<p>I am trying to get the value of a user input in selenium webdriver, however, the webdriver is returning the text from the 'value' attribute instead. Is this a bug in Selenium? How can I get what the user actually entered?</p>

<pre><code>&lt;input id="budget" name="budget" type="text" size="10" maxlength="10" class="exemplifiable" value="100" data-example="20.00"&gt;
</code></pre>

<p><strong>Test Code</strong></p>

<pre><code>locator = 'budget'
element = self.find_element_by_id(locator)
element.send_keys('5') 
value = element.get_attribute('value')
print(value)     
# prints 100 instead of 5
</code></pre>

<blockquote>
  <p>Is this a bug in Selenium?</p>
</blockquote>

<p>No, this is not a bug, behaviour is absolutely correct. </p>

<p>Actually you're getting the attribute value from already found element instead of refreshed element where attribute value already stored with old value in the cache. That's why you're getting previous value. </p>

<p>You should find the same element again after <code>send_keys()</code> with new value and then you'll find the actual result which you want as below :-</p>

<pre><code>locator = 'budget'
element = self.find_element_by_id(locator)
element.send_keys('5') 
value = self.find_element_by_id(locator).get_attribute('value')
print(value)     
</code></pre>

python selenium-webdriver