0

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.

dev tools showing value for last 4 field

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:

dev tools for jse version of quantity

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:

Quantity from webdriver

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

1 Answer 1

1

Interesting!! Can you please try

jse.executeScript("document.getElementById('Quantity').value='324';");

I have tried it on a test page, For me the above code and setAttribute(as you are using) also worked fine. "324" should be typecasted to number in both the cases.

Hope it work for you.

enter image description here enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Wow! That worked! And when I replaced 324 with thew variable '" + productQuantity + "' it STILL worked! I'm stunned and grateful! Thank you so much!!
Not a problem Buddy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.