javascript - 量角器 - 如何验证元素不可见
问题描述
这个问题与这个问题中给出的解决方案密切相关
在我的测试脚本中,我需要转到登录脚本并需要注销,以防浏览器在应用程序中自动登录。因此,按照问题How to create a condition in protractor for when an element exists or not中提供的解决方案,我创建了这个脚本:
beforeEach(function () {
browser.driver.manage().window().maximize();
browser.get(globalVariables.loginMain);
globalVariables.User_Menu_Dropdown.isDisplayed().then(function(Login_Menu) {
if (Login_Menu) {
globalVariables.User_Menu_Dropdown.click();
browser.wait(globalVariables.until.presenceOf(globalVariables.logOut_Button), 3000, 'The Logout menu too long to appear in the DOM');
globalVariables.logOut_Button.click();
browser.wait(globalVariables.until.presenceOf(globalVariables.Email_Input_box), 3000, 'The User Input box too long to appear in the DOM');
} else {
console.log("the app is on the login page")//do nothing
}
});
但是当我运行脚本时,我仍然收到以下错误
"Failed: No element found using locator: By(css selector, img[class="img-thumb-xs mr-1 align-middle"])".
我在这里做错了什么?实现它的最佳方法是什么?
解决方案
您可以在您的情况下使用ExpectedConditions。
var EC = protractor.ExpectedConditions;
// Waits for the element with id 'abc' to be no longer visible on the dom.
browser.wait(EC.invisibilityOf($('#abc')), 5000);
或者您可以使用not条件,这将导致相同的结果
var EC = protractor.ExpectedConditions;
// Waits for the element with id 'abc' to be no longer visible on the dom.
browser.wait(EC.not(EC.visibilityOf($('#abc'))), 5000);
推荐阅读
- reactjs - REDUX SAGA - API 重试同构提取
- c++ - 对“libbgp::BgpFsm::tick()”的未定义引用
- express - 快速路由参数在 firefox 和移动浏览器中出现错误
- asp.net - ASP.NET Core 将图像存储到 SQL Server null
- python - 隐藏 tkinter 小部件与销毁和重新创建它们
- list - Tcl 多个数字在同一字符串内开始
- sql - 天蓝色突触分区表 - 没有性能提升
- python - 使用 HMAC 为 get 请求签名散列有效负载不起作用
- angular - 在 mat-tab-group 上制作粘性标题
- amazon-web-services - 如何在 Redshift 中的时间列中插入时间值?