【问题标题】:Protractor can't find gmail input with id of password量角器找不到密码 id 的 gmail 输入
【发布时间】:2016-03-02 03:37:21
【问题描述】:

我正在尝试设置 Protractor 来测试我的应用程序,但它需要通过 gmail 进行身份验证,我一直在尝试登录:

describe('Vivace Home page', function() {

  var hasClass = function (element, cls) {
    return element.getAttribute('class').then(function (classes) {
      return classes.split(' ').indexOf(cls) !== -1;
    });
  };

  beforeEach(function() {

    browser.ignoreSynchronization = true;
    browser.get('/');

    var emailInput = browser.driver.findElement(by.id('Email'));
    emailInput.sendKeys('paulG@gmail.com')

    var nextButton = browser.driver.findElement(by.id('next'));

    nextButton.click().then(function() {
      browser.pause();
      var passwordInput = browser.driver.findElement(by.id('Passwd'));
      console.log(passwordInput);
      passwordInput.sendKeys('11111');
      // var signInButton = browser.driver.findElement(by.id('signIn'));
    })
  });

  it('should have the correct title', function() {
    expect(browser.getTitle()).toEqual('InRhythm - Vivace');
  });
});

我可以看到 Protractor 打开 gmail 页面,输入电子邮件并单击下一步按钮,当我执行 browser.pause 时,我实际上可以在带有检查器的页面上看到 ID 为“Passwd”的密码输入但我无法访问它来完成我的登录。

删除浏览器时出现此错误。暂停

失败:没有这样的元素:无法找到元素:{"method":"id","selector":"Passwd"}

【问题讨论】:

    标签: javascript angularjs protractor


    【解决方案1】:

    等到become visible:

    var EC = protractor.ExpectedConditions;
    var passwordInput = element(by.id('Passwd'));
    
    browser.wait(EC.visibilityOf(passwordInput), 5000);
    passwordInput.sendKeys('11111');
    

    【讨论】:

    • @WinchenzoMagnifico 好的,很好,已适当更新。谢谢!
    猜你喜欢
    • 2014-04-08
    • 2012-02-24
    • 1970-01-01
    • 2017-11-28
    • 2015-01-31
    • 2013-10-23
    • 1970-01-01
    • 2018-04-20
    • 2018-08-30
    相关资源
    最近更新 更多