实际上,需要设置量角器的实例,因此是书面的
var ptor = protractor.getInstance();
var driver = ptor.driver;
// Switching to frame
ptor.switchTo().frame(driver.findElement(protractor.By.id('NavBarGloablQuickCreate')));
对于上面的代码,要求设置:
Protractor: Failed: protractor.getInstance is not a function
var browser = require("protractor").protractor.browser;
var driver = browser.driver;
But while setting it in the beginning :
for example :
it("Creating Customer",function()
{
var browser = require("protractor").protractor.browser;
browser.ignoreSynchronization = true;
有错误,说:
找不到模块“量角器”
请。帮助
答案 0 :(得分:0)
我在原始答案中缺少.getWebElement()
,但是由于您在评论中说您愿意设置SELENIUM_PROMISE_MANAGER: false
,因此您可以尝试这种方法。请注意,使用此设置后,您所有的代码将需要更改为异步/等待样式,或者可能无法按照您期望的顺序运行。
conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'localhost:4444/wd/hub',
capabilities: {
browserName: 'chrome'
},
specs: ['spec.js'],
SELENIUM_PROMISE_MANAGER: false,
jasmineNodeOpts: {
isVerbose: true,
includeStackTrace: true,
showColors: true,
defaultTimeoutInterval: 3000000
}
};
Spec.js
it('switch to browser', async () => {
await browser.waitForAngularEnabled(false);
await browser.switchTo().frame(element(by.id('NavBarGloablQuickCreate')).getWebElement());
let firstNField = element(by.id("firstname_i"));
console.log(await firstNField.isPresent());
await firstNField.sendKeys('firstN');
console.log(firstNField.getAttribute('value'))
});
旧答案:不异步/等待,您可以尝试一下并让我知道如何吗?
browser.waitForAngularEnabled(false);
browser.switchTo().frame(element(by.id("NavBarGloablQuickCreate")).getWebElement());
browser.driver.sleep(1000);
element(by.id('firstname_i')).sendKeys('Indra');
browser.driver.sleep(1000);