量角器:未定义的 ExpectedConditions.elementToBeClickable
Protractor: ExpectedConditions.elementToBeClickable of Undefined
我试图等待输入加载。所以,我这样使用 expectedconditions.elementToBeClickable:
it('test expected conditions', async function () {
await browser.waitForAngularEnabled(false);
await browser.driver.get('https://www.baidu.com');
var EC = protractor.ExpectedConditions;
await browser.wait(EC.elementToBeClickable(element(by.css('kw'))), 5000);
element(by.css('#kw')).sendKeys('protractor')
element(by.css('#su')).click()
browser.driver.sleep(10000);
});
但是有一条错误信息抛出,是:
Failed: Cannot read property of 'elementToBeClickable' of undefined.
我很确定我可以使用 css 类型的 'kw' 定位输入(我只是想尝试 expectedconditions 以便我可以优化代码。)。我已经导入了必要的 API,它们是:
import { browser, logging, element, by } from 'protractor';
import { protractor } from 'protractor/built/ptor';
所以,谁能告诉我为什么会这样?我该如何解决?非常感谢
导入的主要问题。
您应该像这样从 protractor
模块导入 ExpectedConditions
:
import { ExpectedConditions as EC } from 'protractor';
用法:
await browser.wait(EC.elementToBeClickable(element(by.css('kw'))), 5000);
我试图等待输入加载。所以,我这样使用 expectedconditions.elementToBeClickable:
it('test expected conditions', async function () {
await browser.waitForAngularEnabled(false);
await browser.driver.get('https://www.baidu.com');
var EC = protractor.ExpectedConditions;
await browser.wait(EC.elementToBeClickable(element(by.css('kw'))), 5000);
element(by.css('#kw')).sendKeys('protractor')
element(by.css('#su')).click()
browser.driver.sleep(10000);
});
但是有一条错误信息抛出,是:
Failed: Cannot read property of 'elementToBeClickable' of undefined.
我很确定我可以使用 css 类型的 'kw' 定位输入(我只是想尝试 expectedconditions 以便我可以优化代码。)。我已经导入了必要的 API,它们是:
import { browser, logging, element, by } from 'protractor';
import { protractor } from 'protractor/built/ptor';
所以,谁能告诉我为什么会这样?我该如何解决?非常感谢
导入的主要问题。
您应该像这样从 protractor
模块导入 ExpectedConditions
:
import { ExpectedConditions as EC } from 'protractor';
用法:
await browser.wait(EC.elementToBeClickable(element(by.css('kw'))), 5000);