简体   繁体   English

量角器:sendKeys 不适用于 type="number"

[英]Protractor: sendKeys doesn't work with type="number"

I'm trying to send numeric input using sendKeys but it isn't working.我正在尝试使用sendKeys发送数字输入,但它不起作用。 This is my HTML:这是我的 HTML:

<input type="number" maxlength="3950">

And this is how I'm trying to locate the input box and add a number to it:这就是我尝试定位输入框并为其添加数字的方式:

var input = element(by.css('input'));
input.clear();
browser.sleep(5000);
input.sendKeys('2'); //Here's the error
browser.sleep(1000);
var btn = element(by.css(".btn.btn-action.btn-ok" ));

And this is the error:这是错误:

Failed: No element found using locator: By(css selector, .btn.btn-action.btn-ok)

First off all post the error you are getting, secondly it looks obvious that you are using a very generic selector and you may have more than one input on a given page.首先发布您遇到的错误,其次很明显您正在使用一个非常通用的选择器,并且您可能在给定页面上有多个input Try something unique like,尝试一些独特的东西,比如

var input = element(by.css('input[type='number']'));
input.clear();
input.sendKeys('2'); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM