无法使用 Jasmine(量角器)定位元素
Cannot Locate Element using Jasmine (Protractor)
登录页面是一个非angular页面,当用户登录时,s/he被重定向到主页。主页正在使用 angular.
登录,我用过
browser.ignoreSynchronization = true;
var loginTxt = browser.driver.findElement(by.id("userNameInput"));
var pwdTxt = browser.driver.findElement(by.id("passwordInput"));
var signInBtn = browser.driver.findElement(by.id("submitButton"));
loginTxt.sendKeys("test1");
pwdTxt.sendKeys("password!");
signInBtn.click();
用户登录成功,
我使用以下代码与主页中的元素进行交互。
browser.ignoreSynchronization = false;
var el = element(by.className("btn item-desktop-only inactive-btn"))
el.click();
错误代码:
信息:
失败:等待 Protractor 与页面同步时出错:"both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"
当我删除
browser.ignoreSynchronization = false;
然后我得到一个错误:
Message:
Failed: No element found using locator: By(css selector, .btn.item-desktop-only.inactive-btn)
Stack:
NoSuchElementError: No element found using locator: By(css selector, .btn.item-desktop-only.inactive-btn)
HTML 是:
<button _ngcontent-vsd-c3="" class="btn item-desktop-only inactive-btn" type="button" ng-reflect-klass="btn item-desktop-only" ng-reflect-ng-class="[object Object]"><img _ngcontent-vsd-c3="" class="orders-icon" src="/assets/icons/orders-inactive.png" srcset="/assets/icons/orders-inactive@2x.png 2x,/assets/icons/orders-inactive@3x.png 3x"> Orders </button>
从错误中可以明显看出主页不是 angular app > version 2.
继续
browser.ignoreSynchronization = true;
你能检查定位器是否正确吗?请通过在开发工具中找到它来验证定位器。
人员经验:angular 应用程序版本 < 2 工作正常 browser.ignoreSynchronization = true;
尝试等到定位器存在。
您可以在量角器中使用 ExpectedConditions。
const EC = require('protractor').ExpectedConditions;
let elm = element(by.id('your id'));
browser.wait(EC.presenceOf(e), 10000); //2nd parameter is the max timeout
expect(e.isPresent()).toBeTruthy();
登录页面是一个非angular页面,当用户登录时,s/he被重定向到主页。主页正在使用 angular.
登录,我用过
browser.ignoreSynchronization = true;
var loginTxt = browser.driver.findElement(by.id("userNameInput"));
var pwdTxt = browser.driver.findElement(by.id("passwordInput"));
var signInBtn = browser.driver.findElement(by.id("submitButton"));
loginTxt.sendKeys("test1");
pwdTxt.sendKeys("password!");
signInBtn.click();
用户登录成功, 我使用以下代码与主页中的元素进行交互。
browser.ignoreSynchronization = false;
var el = element(by.className("btn item-desktop-only inactive-btn"))
el.click();
错误代码: 信息: 失败:等待 Protractor 与页面同步时出错:"both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"
当我删除
browser.ignoreSynchronization = false;
然后我得到一个错误:
Message:
Failed: No element found using locator: By(css selector, .btn.item-desktop-only.inactive-btn)
Stack:
NoSuchElementError: No element found using locator: By(css selector, .btn.item-desktop-only.inactive-btn)
HTML 是:
<button _ngcontent-vsd-c3="" class="btn item-desktop-only inactive-btn" type="button" ng-reflect-klass="btn item-desktop-only" ng-reflect-ng-class="[object Object]"><img _ngcontent-vsd-c3="" class="orders-icon" src="/assets/icons/orders-inactive.png" srcset="/assets/icons/orders-inactive@2x.png 2x,/assets/icons/orders-inactive@3x.png 3x"> Orders </button>
从错误中可以明显看出主页不是 angular app > version 2.
继续
browser.ignoreSynchronization = true;
你能检查定位器是否正确吗?请通过在开发工具中找到它来验证定位器。
人员经验:angular 应用程序版本 < 2 工作正常 browser.ignoreSynchronization = true;
尝试等到定位器存在。
您可以在量角器中使用 ExpectedConditions。
const EC = require('protractor').ExpectedConditions;
let elm = element(by.id('your id'));
browser.wait(EC.presenceOf(e), 10000); //2nd parameter is the max timeout
expect(e.isPresent()).toBeTruthy();