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:
jse.executeScript("document.getElementById('PaymentInfo_CCLast4Digits').setAttribute('value', '" + lastFour + "')");
As you can see, by the dev tools and the firld, everything is as it should be.
Now, I also have a field called Quantity. Here is the jse code for that:
jse.executeScript("document.getElementById('Quantity').setAttribute('value', '" + productQuantity + "')");
And this is what happens:
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:
driver.findElement(By.id("Quantity")).sendKeys(productQuantity);
then it behaves as expected:
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:
1) Last 4 CC field is "type = text" where Quantity field is "type = number"
2) The Quantity field has those little up and down arrows, presumably because it's type = number
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?
Thank you much!
Scott




