27
27
import java .util .Map ;
28
28
import java .util .concurrent .Callable ;
29
29
30
+ import org .apache .commons .lang3 .StringUtils ;
30
31
import org .htmlunit .ScriptResult ;
31
32
import org .htmlunit .corejs .javascript .ScriptRuntime ;
33
+ import org .htmlunit .corejs .javascript .Scriptable ;
32
34
import org .htmlunit .corejs .javascript .ScriptableObject ;
33
35
import org .htmlunit .html .DisabledElement ;
34
36
import org .htmlunit .html .DomElement ;
47
49
import org .htmlunit .html .HtmlTextArea ;
48
50
import org .htmlunit .html .impl .SelectableTextInput ;
49
51
import org .htmlunit .javascript .HtmlUnitScriptable ;
52
+ import org .htmlunit .javascript .host .css .CSSStyleDeclaration ;
53
+ import org .htmlunit .javascript .host .dom .DOMTokenList ;
50
54
import org .htmlunit .javascript .host .html .HTMLElement ;
51
55
import org .openqa .selenium .By ;
52
56
import org .openqa .selenium .Dimension ;
@@ -404,24 +408,36 @@ public String getAttribute(final String name) {
404
408
public String getDomProperty (final String name ) {
405
409
assertElementNotStale ();
406
410
407
- final String lowerName = name .toLowerCase ();
408
-
409
411
final HtmlUnitScriptable scriptable = element_ .getScriptableObject ();
410
412
if (scriptable != null ) {
411
- if (!ScriptableObject .hasProperty (scriptable , lowerName )) {
413
+ final Object propValue = ScriptableObject .getProperty (scriptable , name );
414
+ if (Scriptable .NOT_FOUND == propValue ) {
412
415
return null ;
413
416
}
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 );
415
431
}
416
432
417
433
// js disabled, fallback to some hacks
418
- if ("disabled" .equals (lowerName )) {
434
+ if ("disabled" .equals (name )) {
419
435
if (element_ instanceof DisabledElement ) {
420
436
return trueOrFalse (((DisabledElement ) element_ ).isDisabled ());
421
437
}
422
438
}
423
439
424
- if ("checked" .equals (lowerName )) {
440
+ if ("checked" .equals (name )) {
425
441
if (element_ instanceof HtmlCheckBoxInput ) {
426
442
return trueOrFalse (((HtmlCheckBoxInput ) element_ ).isChecked ());
427
443
}
@@ -430,7 +446,7 @@ else if (element_ instanceof HtmlRadioButtonInput) {
430
446
}
431
447
}
432
448
433
- final String value = element_ .getAttribute (lowerName );
449
+ final String value = element_ .getAttribute (name );
434
450
if (ATTRIBUTE_NOT_DEFINED == value ) {
435
451
return null ;
436
452
}
@@ -467,6 +483,18 @@ else if (element_ instanceof HtmlRadioButtonInput) {
467
483
}
468
484
}
469
485
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
+
470
498
return value ;
471
499
}
472
500
0 commit comments