How to assert web element is non editable selenium c#
Alberto last edited by
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
IWebElementI am getting (
Text,Display,Enabled,Location,Selected,Size and TagName). I am getting
divso at last I used
TagNamefor 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 ,
- 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.
- You can't achieve it using enabled attribute because it always return true
Is enabled works only when the element has attribute called disabled , else it always returns true.
- First uniquely find the div element
- Then verify the attribute value 'data-qa' is equal to 'non-editable-location-label' using getattribute