How to assert web element is non editable selenium c#

  • Depending on a condition a input or a div gets render on browser. In my UI automation test I need to assert the div is a non-editable element.

    I achieved this as-

    var readOnlyLocation = Driver.FindElement(By.CssSelector("[data-qa='non-editable-location-label']")); 

    In instance of IWebElement I am getting (Text,Display,Enabled,Location,Selected,Size and TagName). I am getting Enabled property value true for div so at last I used TagName for assertion. I wanted to ask is there a better way to achieve this assertion?

  • I am.not sure what you are trying to do . Instead saying a div or input. Explain it in simpler terms like a text box or placeholder or button etc . So that everyone understands the use case

    Coming to your question :

    It seems like ,

    1. u want to find a div element and verify it is disabled

    What you are doing in the test is , getting all non editable elements and checking if it's a div


    It might find some other div element than the one you really interested in.

    Your test might fail even if your target div is enabled but the Dom had a different div which was disabled.

    1. You can't achieve it using enabled attribute because it always return true

    This is because the div element is not disabled using disabled property but JavaScript.

    Is enabled works only when the element has attribute called disabled , else it always returns true.

    proper Solution:

    1. First uniquely find the div element
    2. Then verify the attribute value 'data-qa' is equal to 'non-editable-location-label' using getattribute

Suggested Topics

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