0

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']")); 
readOnlyLocation.TagName.Should().Be("div");
readOnlyLocation.Text.Should().Be("extected_text");

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?

1

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

Problem:

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

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.