I want to validate that field is not editable. Code I am trying is:


But this is not working as it successfully pass this and according to my TC this is incorrect

div of above element (which is not editable) looks like:

<div tabindex="-1" role="gridcell" comp-id="1534" col-id="FGA_PROCESSOR" class="ag-cell ag-cell-not-inline-editing ag-cell-with-height ag-cell-value ag-cell-no-focus" style="width: 97px; left: 1864px; "></div>

div of editable field looks like:

<div tabindex="-1" role="gridcell" comp-id="1532" col-id="fgaConfigDescription" class="ag-cell ag-cell-with-height ag-cell-value ag-cell-focus ag-cell-inline-editing ag-column-hover" style="width: 175px; left: 1581px; "><input class="ag-cell-edit-input" type="text"></div> 

Only difference between editable and non editable fields is on INPUT tag.

I just need to make sure that the field is not editable and doesn't accept any text/data

  • When you say "it passes" you mean that the test ends green or that the "PleaseCHECK" text is placed on the input? If you do a getText after the sendKeys it returns the inputted text? Jul 22, 2019 at 10:01

4 Answers 4


You can validate this by using try and catch also,
look at this:

public static boolean isElementPresent(By by)
            return true;
        catch(Exception e){
            return false;

Now use this method in your test class-

By value1= By.xpath(".//div[@comp-id='1534']/input");
By value2= By.xpath(".//div[@comp-id='1534']");

Assert.assertEquals(isElementPresent(value1), false, "Field is editable");

As per your scenario, If you validate that INPUT tag is not available, then you could identify text field is not editable.

Try this piece of code:

    List lstElmnt=driver.findElements(By.xpath("//div[@comp-id='1494']/input")); 
       System.out.println("Text field is not editable"); 
        Assert.fail("Text field is editable"); 
  • INPUT tag is only visible when you click in that field. @user40540
    – Dolly
    Jul 22, 2019 at 12:00
`//Fist click on an element
//Then validate Input tag
List <WebElement> lstElmnt=driver.findElements(By.xpath("//div[@comp-id='1494']/input")); if(lstElmnt.size()<=0){
 System.out.println("Text field is not editable"); }
else { Assert.fail("Text field is editable"); }`

You could specifically check for the not-inline-editing part of the Class:


Above should check the comp-id entry also has a class that contains (denoted by ^=) 'cell-not-inline-editing'.

  • But this assumes that the CSS rule behaves correct; one can simply write an empty CSS class - which still allows editing. Jul 22, 2019 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.