Selenium webdriver how to get the allowed status of an element angularjs Li

I have the following page angular.jsper page. Displayed items angular.js Li. One of them is greyed, the other is included. When I use the method Selenium webdriver .isEnabled(), both greyed out and enabled objects return "enabled".

First question: how do I get .isEnabled()to work with this type of element? Q The second question is that the webdriver will not do this, and I need xpath, I think, I could use something like this:

$x("//li[@class ='ng-scope disabled' and @id='actionCUSTARD']")
$x("//li[@class ='ng-scope' and @id='actionRHUBARB']")

The first returns something only if the given identifier is disabled, the second - only if the given identifier is included, it can be built into the Java method to check that the element is enabled or disabled for the given identifier. Is there an easier way to do this?

</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>   
+4
source share
2 answers

The item is probably disabled if the style is pointer-eventsset to none, which is not considered .isEnabled(). If so, you can evaluate the CSS value returned .getCssValue:

boolean isEnabled = !"none".equals(element.getCssValue("pointer-events"));

Or with a piece of JavaScript:

boolean isEnabled = (boolean)((JavascriptExecutor)driver).executeScript(
    "return window.getComputedStyle(arguments[0], null).getPropertyValue('pointer-events') === 'none'"
    , element);

You can also determine the state by checking for a class disable, but it does not guarantee that the element is disabled by the implemented style.

+1

By.id isEnabled(), : -

WebElement el = driver.findElement(By.id("actionRHUBARB"))

WebElement el = driver.findElement(By.id("actionCUSTARD"))

: -

if(el.isEnabled()) {
   //do your stuff
}

: - findElement , DOM, NoSuchElementException

, , selenium enabled, By.cssSelector, : -

WebElement el = driver.findElement(By.cssSelector(":not(.disabled)[id = 'actionRHUBARB']"));
//it will find enabled element with id actionRHUBARB

WebElement el = driver.findElement(By.cssSelector(":not(.disabled)[id = 'actionCUSTARD']"));
//it will throw NoSuchElementException because it is not enabled

, ...:)

0

Source: https://habr.com/ru/post/1649396/


All Articles