0

I have below HTML tags, i want to pass/sendkeys to input box.

<input type="number" value="null" step="1" min="0" max="2" class="abc">

'sendkeys' is not working since above input 'type' is "number".(with sendkeys it's accepting only "string" values).

1 Answer 1

1

I would think the SendKeys() would do it. So far I know you can send whatever you want as string and the page should manipulate it as int. However, if that's not the case you can use JavaScriptExecutor to set the value of attribute value

    string value = "1234";
    ((IJavaScriptExecutor) Driver).ExecuteScript(
        "document.querySelector(\"[type='number'][step='1']\").setAttribute('value','" + value + "');");

Note: the code above is C# code and inside the querySelector you can use any valid cssSelector

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

1 Comment

Saifur has a great suggestion. Inside of an input text box, the server is going to initially parse it as a string anyway. Even if it is a string, is SendKeys trying to put in a quoted value into the box, or can you put in digits unquoted. You could just let the server cast the string to an int anyway.

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.