Skip to content
Advertisement

Selenium webelement clickable or not JAVA

So there is not a isClickable() function in selenium. There is however an isEnabled() that works most of the time (in combination with isDisplayed()), but not always.

I find myself in such a situation. I have an btn (found by css selector) that is greyed out and not clickable but I dont find any way to verify this. (isEnabled always true, and is always displayed)/ The element itself has no attributes nor values that differ from the same btn that ís clickable.

I am out of ideas, I tried the try/catch with the expectedConditions.elementToBeClickable(element) but thats always returning true as well.

Does anyone have a solution for me or a different way? Maybe I can verify the CSS bit (never done it before)? Is that a valid assertion tho?

Thanks

Advertisement

Answer

I see a difference when button is available which is,

<input class="form-control qty" name="qty" type="number" value="1" min="1">

you can have the below code block to check when to click :

code :

try {
    if (driver.findElements(By.xpath("//input[@name='qty' and @class='form-control qty' and @type='number']")).size()  > 0 ) {
        System.out.println("This means button is available to click");
        // code to click on button should be written here
    }
    else {
        System.out.println("Button must be greyed out, if you are seeing this");
        // do some stuff to make button available
    }
}
catch(Exception e) {
    System.out.println("Check the code again, looks like some issue. ");
    e.printStackTrace();
}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement