打字稿错误:量角器中的“未知”类型不存在属性“清除”或“发送”

时间:2019-08-29 18:31:37

标签: node.js typescript jasmine protractor

无法使用打字稿在量角器中使用clear和sendKeys。我是否缺少任何依赖项,因为即使单击也会引发错误?

我尝试了与Protractor clear() not working不同的解决方案 但似乎没有任何作用

 async setEmail(username: String) {
        let emailField = await browser.wait(until.presenceOf(element(by.css("#username"))), DEFAULT_WAIT_TIME_SECONDS * 1000, 'Email field never appeared.');
     /* await emailField.clear().then(()=>{
           emailField.sendKeys(username);
       });*/
    emailField.clear();
    emailField.sendKeys(username);
       /* await emailField.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, 'a'));
        await emailField.sendKeys(username);*/
    }

E /启动器-错误:TSError:⨯无法编译TypeScript: e2e / common / pageObjects / loginLogoutWorkflow / LoginPageEntities.ts(64,16):错误TS2339:类型“未知”上不存在属性“清除”。 e2e / common / pageObjects / loginLogoutWorkflow / LoginPageEntities.ts(65,17):错误TS2339:属性“ sendKeys”在“未知”类型上不存在。

2 个答案:

答案 0 :(得分:0)

这应该有效

async setEmail(username: String) {
  let emailField = element(by.css("#username"));
  await browser.wait(
    protractor.ExpectedConditions.presenceOf(emailField), 
    DEFAULT_WAIT_TIME_SECONDS * 1000, 
    'Email field never appeared.'
  );
  await emailField.clear();
  await emailField.sendKeys(username);
}

答案 1 :(得分:0)

您也可以尝试以下代码段。

async setEmail(username: String) {

var EC = browser.ExpectedConditions;
let emailField = element(by.css("#username"));


await browser.wait(EC.visibilityOf(emailField),10000);

await emailField.clear();
await emailField.sendKeys(username);
}