jasmine - 无法使用 Jasmine(量角器)定位元素
问题描述
登录页面是一个非角度页面,当用户登录时,他/她会被重定向到主页。主页使用角度。
对于登录,我使用过
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();
错误代码:消息:失败:等待量角器与页面同步时出错:“angularJS 可测试性和角度可测试性都未定义。这可能是因为这是一个非角度页面,或者因为您的测试涉及客户端导航,这可能会干扰量角器的引导。有关详细信息,请参阅http://git.io/v4gXM "
当我删除
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;
你能检查定位器是否正确。请通过在开发工具中找到它来验证定位器。
人员经验:角度应用程序版本 < 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();
推荐阅读
- python - how to fix "index 3 is out of bounds for axis 1 with size 3" in one-hot encoding?
- gatling - 我是 Gatling Tool 的新手。我们如何在 gatling 工具中进行协调和参数化
- laravel - 如何在 Laravel Blade @can 标签中检查两个用户的授权
- javascript - 从列表中获取第二个,而不是使用 jquery 选择一个
- scope - 当声明符(我的/状态)在 for 块中时会发生什么?
- c++ - QTreeWidgetItem 有两个父母
- java - 如何在没有任何库方法的情况下将字符串的 ArrayList 转换为整数?
- java - DatabaseException:无法将 java.lang.Long 类型的对象转换为类型(Model.class)
- bash - 与 unix 目录中的文件计数不匹配
- c# - 启用 MFA 的移动应用程序的身份验证过程 Sharepoint 在线帐户