From 7bbc77283388ac19a350fe9a938f9c4996d28bf9 Mon Sep 17 00:00:00 2001 From: AutomatedTester Date: Wed, 13 May 2026 21:15:35 +0100 Subject: [PATCH] [JavaScript] Correct handling for older browsers and missing casing This brings back IE11 support and fixes the case where there is className Fixes #17448 and #17447 --- javascript/atoms/test/attribute_typescript_test.html | 4 ++-- javascript/atoms/typescript/get-attribute.ts | 5 +++-- .../selenium/webdriver/common/element_attribute_tests.py | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/javascript/atoms/test/attribute_typescript_test.html b/javascript/atoms/test/attribute_typescript_test.html index bcf45e2cce573..a795cb78187a3 100644 --- a/javascript/atoms/test/attribute_typescript_test.html +++ b/javascript/atoms/test/attribute_typescript_test.html @@ -55,8 +55,8 @@ assertAttributeEquals(assert, null, byId('checky'), 'never_there'); }); - QUnit.test('should return null for missing class attribute', function (assert) { - assertAttributeEquals(assert, null, byId('no-class'), 'class'); + QUnit.test('should return empty string for element with no class attribute', function (assert) { + assertAttributeEquals(assert, '', byId('no-class'), 'class'); }); QUnit.test('should return an empty string when attribute value is empty', function (assert) { diff --git a/javascript/atoms/typescript/get-attribute.ts b/javascript/atoms/typescript/get-attribute.ts index 01a263d380041..cddfa56d52381 100644 --- a/javascript/atoms/typescript/get-attribute.ts +++ b/javascript/atoms/typescript/get-attribute.ts @@ -21,6 +21,7 @@ * correct property name. */ const PROPERTY_ALIASES: Record = { + 'class': 'className', 'readonly': 'readOnly', }; @@ -178,9 +179,9 @@ return String(getProperty(element, name)); } - const propName = PROPERTY_ALIASES[attribute] || attribute; + const propName = PROPERTY_ALIASES[name] || attribute; - if (BOOLEAN_PROPERTIES.includes(name)) { + if (BOOLEAN_PROPERTIES.indexOf(name) !== -1) { const hasAttr = getAttribute(element, attribute) !== null; const propValue = getProperty(element, propName); return hasAttr || !!propValue ? 'true' : null; diff --git a/py/test/selenium/webdriver/common/element_attribute_tests.py b/py/test/selenium/webdriver/common/element_attribute_tests.py index a1717111c7b98..a5c5683c5f895 100644 --- a/py/test/selenium/webdriver/common/element_attribute_tests.py +++ b/py/test/selenium/webdriver/common/element_attribute_tests.py @@ -166,6 +166,12 @@ def test_should_return_value_of_class_attribute_of_an_element(driver, pages): assert "header" == classname +def test_should_return_empty_string_for_class_attribute_when_no_class_set(driver, pages): + pages.load("simpleTest.html") + element = driver.find_element(By.ID, "oneline") + assert "" == element.get_attribute("class") + + # Disabled due to issues with Frames # def test_should_return_value_of_class_attribute_of_an_element_after_switching_iframe(driver, pages): # pages.load("iframes.html")