There is no other way in Selenium but you need to handle it with your language (Java, C#)
string nameRequired = elemntvalue.getAttribute("required");
if (nameRequired == null) {
//Means "required" attribute is not set OR name element is not a required field
} else if (nameRequired.contains("true")) {
//Means "required" attribute is set OR name element is a required field
} else {
//If it has any value then do something as required
}
Get the value of the given attribute of the element. Will return the current value, even if this has been modified after the page has been loaded.
More exactly, this method will return the value of the property with the given name, if it exists. If it does not, then the value of the attribute with the given name is returned. If neither exists, null is returned.
The "style" attribute is converted as best can be to a text representation with a trailing semi-colon.
The following are deemed to be "boolean" attributes, and will return either "true" or null:
async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking, selected, truespeed, willvalidate
Finally, the following commonly mis-capitalized attribute/property names are evaluated as expected:
If the given name is "class", the "className" property is returned.
If the given name is "readonly", the "readOnly" property is returned.
Note: The reason for this behavior is that users frequently confuse attributes and properties. If you need to do something more precise, e.g., refer to an attribute even when a property of the same name exists, then you should evaluate Javascript to obtain the result you desire.
Parameters:
name - The name of the attribute.
Returns:
The attribute/property's current value or null if the value is not set.