如何检查量角器是否不可单击某个元素?

编程入门 行业动态 更新时间:2024-10-27 18:23:03
本文介绍了如何检查量角器是否不可单击某个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

测试量角器是否可点击元素 很简单,但是我一直抓挠头试图弄清楚如何检查元素是否可点击

It's trivial to test if an element is clickable with Protractor, but I'm stuck scratching my head trying to figure out how to check if an element is not clickable.

我试图将click函数包装在try/catch中,以便当尝试单击时引发错误时,它应该捕获并让测试通过;但是,这不起作用.

I've attempted to wrap the click function in a try/catch so that when an error is thrown when trying to click it should catch it and let the test pass; however, this does not work.

这是我执行检查的方法的代码:

Here is my code for the method that does the check:

return this.shouldSeeDisabledFunds() .then(function() { var clickable = true; try { fundsElem.first().click(); } catch (e) { clickable = false; console.log(clickable); } finally { console.log(clickable); } console.log(clickable); // All the way through, clickable is still true, and the console log in the // catch is not called. I believe this is because click is asynchronous. }) ;

推荐答案

我找到了适用于此的解决方案.当click()返回一个承诺时,您可以简单地.then离开它,并放入成功的单击处理程序,并覆盖catch处理程序以执行任何操作,如果该元素不可单击,则使测试通过.

I have found a solution that works for this. As click() returns a promise you can simply .then off of it and throw in the successful click handler and override the catch handler to do nothing which makes the test pass if the element is not clickable.

return this.shouldSeeDisabledFunds() .then(function() { fundsElem.first().click() .then( function() { throw "Can click Funds element that should be disabled"; }, function() {} ) ; }) ;

更多推荐

如何检查量角器是否不可单击某个元素?

本文发布于:2023-11-22 23:11:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619291.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:量角器   单击   元素

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!