面对将IP发送到<div>内的输入类的问题

时间:2016-09-20 18:00:00

标签: protractor

我尝试了这些......没有一个有效,任何提示都会......

this.title = 'Diagnostic Tools';
it('should have a title', function() {

   browser.driver.get('https://URL');
   browser.ignoreSynchronization = true;
   browser.driver.findElement(by.id('username')).sendKeys('user');
   browser.driver.findElement(by.id('password')).sendKeys('pass123');
   browser.driver.findElement(by.name('login')).click();
   browser.waitForAngular();
   expect(browser.getTitle()).toContain('Diagnostic Tools');
   element(by.linkText("TOOLS")).click();
   element(by.name('server_ip')).sendKeys('1.1.1.1');

   });
});

单击“工具”后尝试了3种方法。添加睡眠btw click&amp;发送也没有帮助。

element(by.name('server_ip')).sendKeys('1.1.1.1');
element(by.cssContainingText('input[name="server_ip"]')).sendKeys('1.1.1.1');
element(by.css('server_ip')).sendKeys('1.1.1.1');

输入类:

<i><div class="form-group required ng-scope" ng-repeat="(param_key, param_value) in selectedTool.params">
          <label class="col-sm-2 control-label ng-binding">IP (s)</label>
          <div class="col-sm-4">
            <input style="" required="required" pattern="[ ]*((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})( (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})*[ ]*" 
class="form-control ng-valid-pattern ng-valid-maxlength ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" 
name="server_ip" ng-model="toolInput[param_key]" ng-required="true" ng-attr-pattern="{{param_value.pattern}}" ng-attr-type="{{param_value.type}}" ng-attr-min="{{param_value.min}}" ng-attr-max="{{param_value.max}}" ng-attr-maxlength="{{param_value.maxlength}}">
          </div>
          <div class="col-sm-6">
            <span class="help-block ng-binding">Can be multiple space separated ips.</span>
          </div>

1 个答案:

答案 0 :(得分:0)

在发送密钥之前,您需要explicitly wait才能看到元素

var EC = protractor.ExpectedConditions;
var serverIP = element(by.name("server_ip"));

browser.wait(EC.visibilityOf(serverIP), 5000);
serverIP.sendKeys("1.1.1.1");