0

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

  • 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? – João Farias Jul 22 at 10:01
0

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

public static boolean isElementPresent(By by)
    {
        try{            
            driver.findElement(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']");

driver.findElement(value2).click();
Assert.assertEquals(isElementPresent(value1), false, "Field is editable");
0

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"); 
     }
  • INPUT tag is only visible when you click in that field. @user40540 – Dolly Jul 22 at 12:00
0
`//Fist click on an element
driver.findElement(By.xpath("//div[@comp-id='1494']")).click();
//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"); }`
-1

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

driver.findElement(By.cssSelector("div[comp-id='1494'][class^='cell-not-inline-editing']"));

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. – João Farias Jul 22 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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