title: Using JavaScriptExecutor in Selenium with Java - It takes the value but does not display it in the field
body: <p>Because of some of the things I am doing with my automation, I am trying to keep numbers as ints, text as String types,etc. WebDriver doesn’t “sendKeys” when they’re integers, so I did it using javascript. The first one I did was the credit card last 4 digits field, and I was successful with this line of code:</p>
  
  <p><code>jse.executeScript("document.getElementById('PaymentInfo_CCLast4Digits').setAttribute('value', '" + lastFour + "')");</code></p>
  
  <p>As you can see, by the dev tools and the firld, everything is as it should be.</p>
  
  <p><a href="https://i.stack.imgur.com/JPMVz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JPMVz.png" alt="dev tools showing value for last 4 field"></a></p>
  
  <p>Now, I also have a field called Quantity. Here is the jse code for that:</p>
  
  <p><code>jse.executeScript("document.getElementById('Quantity').setAttribute('value', '" + productQuantity + "')");</code></p>
  
  <p>And this is what happens:</p>
  
  <p><a href="https://i.stack.imgur.com/zhWMQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zhWMQ.png" alt="dev tools for jse version of quantity"></a></p>
  
  <p>Now, as you can see, the value is 324, but it will not show up in the quantity field. BUT, if I change the variable type to String, and pass it through normal webdriver:</p>
  
  <p><code>driver.findElement(By.id("Quantity")).sendKeys(productQuantity);</code></p>
  
  <p>then it behaves as expected:</p>
  
  <p><a href="https://i.stack.imgur.com/4jMvj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4jMvj.png" alt="Quantity from webdriver"></a></p>
  
  <p>Does anyone know why this would happen? Here are the differences as I see them in the last 4 of CC field where it works with jse, and the Quantity field, where it does not:</p>
  
  <p>1) Last 4 CC field is "type = text" where Quantity field is "type = number"</p>
  
  <p>2) The Quantity field has those little up and down arrows, presumably because it's type = number</p>
  
  <p>Anything else I'm missing? Is anyone else experienced enough with this to understand why 324 doesn't show up in the Quantity field when I send it with jse, despite the fact that the dev tools show that the value is indeed 324 and it does show when I send it through Webdriver as a String?</p>
  
  <p>Thank you much!</p>
  
  <p>Scott</p>