Selenium webdriver如何获得angularjs Li元素的启用状态
发布时间:2020-12-17 17:07:25 所属栏目:安全 来源:网络整理
导读:我在页面上有以下angular.js.显示的项目是angular.js Li项目.一个是灰色的,另一个是启用的.当我使用Selenium webdriver方法.isEnabled()时,灰色和启用的项都返回“启用”. 第一个问题是如何使用.isEnabled()来处理这种类型的元素? Q 第二个问题是,假设webdr
我在页面上有以下angular.js.显示的项目是angular.js Li项目.一个是灰色的,另一个是启用的.当我使用Selenium webdriver方法.isEnabled()时,灰色和启用的项都返回“启用”.
第一个问题是如何使用.isEnabled()来处理这种类型的元素? $x("//li[@class ='ng-scope disabled' and @id='actionCUSTARD']") $x("//li[@class ='ng-scope' and @id='actionRHUBARB']") 第一个返回的东西只有在给定的id被禁用时才会返回,第二个只在给定的Id被启用时返回,这可以构建到Java方法中以检查对于给定的id,元素是启用还是禁用.有更简单的方法吗? </li> <li id="actionRHUBARB" class="ng-scope" on="deriveInvokeType(action)" ng-switch="" ng-class="{'disabled': false}" ng-repeat="action in getActionList()"> <!-- ngSwitchWhen: LINK_DYNAMIC --> <!-- ngSwitchWhen: NO_INVOKE_PERMISSION --> <!-- ngSwitchDefault: --> <a class="ng-scope ng-binding" ng-click="doAction(action)" ng-switch-default="" href=""></a> </li> <li id="actionCUSTARD" class="ng-scope disabled" on="deriveInvokeType(action)" ng-switch="" ng-class="{'disabled': true}" ng-repeat="action in getActionList()"> <!-- ngSwitchWhen: LINK_DYNAMIC --> <!-- ngSwitchWhen: NO_INVOKE_PERMISSION --> <!-- ngSwitchDefault: --> <a class="ng-scope ng-binding" ng-click="doAction(action)" ng-switch-default="" href=""></a> </li> 解决方法
该元素可能被禁用,并且样式指针事件设置为none,而不考虑.isEnabled().如果是这种情况,您可以评估.getCssValue返回的CSS值:
boolean isEnabled = !"none".equals(element.getCssValue("pointer-events")); 或者使用一段JavaScript: boolean isEnabled = (boolean)((JavascriptExecutor)driver).executeScript( "return window.getComputedStyle(arguments[0],null).getPropertyValue('pointer-events') === 'none'",element); 您还可以通过检查类禁用的存在来确定状态,但不能保证实现的样式禁用该元素. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |