量角器找不到密码 ID 的 Gmail 输入

Protractor can't find gmail input with id of password

本文关键字:Gmail 输入 ID 找不到 密码 量角器      更新时间:2023-09-26

我正在尝试设置量角器来测试我的应用程序,但它需要通过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');
  });
});

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

当我删除浏览器时收到此错误。

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

等待它变得可见:

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