2727import java .util .Map ;
2828import java .util .concurrent .Callable ;
2929
30+ import org .apache .commons .lang3 .StringUtils ;
3031import org .htmlunit .ScriptResult ;
3132import org .htmlunit .corejs .javascript .ScriptRuntime ;
33+ import org .htmlunit .corejs .javascript .Scriptable ;
3234import org .htmlunit .corejs .javascript .ScriptableObject ;
3335import org .htmlunit .html .DisabledElement ;
3436import org .htmlunit .html .DomElement ;
4749import org .htmlunit .html .HtmlTextArea ;
4850import org .htmlunit .html .impl .SelectableTextInput ;
4951import org .htmlunit .javascript .HtmlUnitScriptable ;
52+ import org .htmlunit .javascript .host .css .CSSStyleDeclaration ;
53+ import org .htmlunit .javascript .host .dom .DOMTokenList ;
5054import org .htmlunit .javascript .host .html .HTMLElement ;
5155import org .openqa .selenium .By ;
5256import org .openqa .selenium .Dimension ;
@@ -404,24 +408,36 @@ public String getAttribute(final String name) {
404408 public String getDomProperty (final String name ) {
405409 assertElementNotStale ();
406410
407- final String lowerName = name .toLowerCase ();
408-
409411 final HtmlUnitScriptable scriptable = element_ .getScriptableObject ();
410412 if (scriptable != null ) {
411- if (!ScriptableObject .hasProperty (scriptable , lowerName )) {
413+ final Object propValue = ScriptableObject .getProperty (scriptable , name );
414+ if (Scriptable .NOT_FOUND == propValue ) {
412415 return null ;
413416 }
414- return ScriptRuntime .toCharSequence (ScriptableObject .getProperty (scriptable , lowerName )).toString ();
417+
418+ if (propValue instanceof CSSStyleDeclaration ) {
419+ return ((CSSStyleDeclaration ) propValue ).getCssText ();
420+ }
421+
422+ if (propValue instanceof DOMTokenList ) {
423+ final String value = ((DOMTokenList ) propValue ).getValue ();
424+ if (value != null ) {
425+ return '[' + String .join (", " , StringUtils .split (value , " \t \r \n \u000C " )) + ']' ;
426+ }
427+ return "" ;
428+ }
429+
430+ return ScriptRuntime .toString (propValue );
415431 }
416432
417433 // js disabled, fallback to some hacks
418- if ("disabled" .equals (lowerName )) {
434+ if ("disabled" .equals (name )) {
419435 if (element_ instanceof DisabledElement ) {
420436 return trueOrFalse (((DisabledElement ) element_ ).isDisabled ());
421437 }
422438 }
423439
424- if ("checked" .equals (lowerName )) {
440+ if ("checked" .equals (name )) {
425441 if (element_ instanceof HtmlCheckBoxInput ) {
426442 return trueOrFalse (((HtmlCheckBoxInput ) element_ ).isChecked ());
427443 }
@@ -430,7 +446,7 @@ else if (element_ instanceof HtmlRadioButtonInput) {
430446 }
431447 }
432448
433- final String value = element_ .getAttribute (lowerName );
449+ final String value = element_ .getAttribute (name );
434450 if (ATTRIBUTE_NOT_DEFINED == value ) {
435451 return null ;
436452 }
@@ -467,6 +483,18 @@ else if (element_ instanceof HtmlRadioButtonInput) {
467483 }
468484 }
469485
486+ if ("multiple" .equals (lowerName )) {
487+ if (element_ instanceof HtmlSelect ) {
488+ return "true" ;
489+ }
490+ }
491+
492+ if ("selected" .equals (lowerName )) {
493+ if (element_ instanceof HtmlOption ) {
494+ return trueOrNull (((HtmlOption ) element_ ).isSelected ());
495+ }
496+ }
497+
470498 return value ;
471499 }
472500
0 commit comments