How to validate that user is not able to enter any data in the given field using selenium java



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

    driver.findElement(By.xpath("//div[@comp-id='1494']")).click();
    driver.findElement(By.xpath("//div[@comp-id='1494']")).sendKeys("PleaseCHECK");
    

    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



  • 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")); 
         if(lstElmnt.size()<=0)
         { 
           System.out.println("Text field is not editable"); 
         } 
        else 
         { 
            Assert.fail("Text field is editable"); 
         }
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2