@@ -67,10 +67,6 @@ open class ElementCreator<out PARENT_TYPE : Element>(
6767
6868 val id: String = mutAttributes.computeIfAbsent(" id" ) { JsonPrimitive (" K" + browser.generateId()) }.content
6969 val htmlDoc = browser.htmlDocument.get()
70- val createElementStatement = when (namespace) {
71- null -> " document.createElement(tag);"
72- else -> " document.createElementNS(\" ${namespace} \" , tag);"
73- }
7470 when {
7571 htmlDoc != null -> {
7672 val parentElement = when (element) {
@@ -92,14 +88,16 @@ open class ElementCreator<out PARENT_TYPE : Element>(
9288 }
9389
9490 element.browser.isCatchingOutbound() != null -> {
91+
9592 // language=JavaScript
9693 val createElementJs = """
9794let tag = {};
9895let attributes = {};
9996let myId = {};
10097let parentId = {};
10198let insertBefore = {};
102- let newEl = $createElementStatement
99+ let namespace = {};
100+ let newEl = namespace ? document.createElementNS(namespace, tag) : document.createElement(tag);
103101newEl.setAttribute("id", myId);
104102for (const key in attributes) {
105103 if ( key !== "id") {
@@ -114,10 +112,11 @@ if (insertBefore !== undefined) {
114112} else {
115113 parentElement.appendChild(newEl);
116114}
117- """
115+ """
116+
118117 browser.callJsFunction(
119- createElementJs, JsonPrimitive (tag), JsonObject (mutAttributes), id.json ,
120- JsonPrimitive (element.id), JsonPrimitive (insertBefore ? : " " ), JsonPrimitive (elementsCreatedCount)
118+ createElementJs, JsonPrimitive (tag), JsonObject (mutAttributes), JsonPrimitive (id) ,
119+ JsonPrimitive (element.id), JsonPrimitive (insertBefore ? : " " ), JsonPrimitive (elementsCreatedCount), JsonPrimitive (namespace ? : " " )
121120 )
122121 }
123122
@@ -130,12 +129,13 @@ let attributes = {};
130129let myId = {};
131130let parentId = {};
132131let insertBefore = {};
133- let newEl = document.createElement(tag);
134- if (attributes["id"] === undefined) {
132+ let namespace = {};
133+ let newEl = namespace ? document.createElementNS(namespace, tag) : document.createElement(tag);
134+ if (!attributes["id"]) {
135135 newEl.setAttribute("id", myId);
136136}
137137for (const key in attributes) {
138- newEl.setAttribute(key, attributes[key]);
138+ newEl.setAttribute(key, attributes[key]);
139139}
140140let parentElement = document.getElementById(parentId);
141141let startNode = document.getElementById(insertBefore)
@@ -145,10 +145,10 @@ if (insertBefore !== undefined) {
145145} else {
146146 parentElement.appendChild(newEl);
147147}
148- """
148+ """
149149 element.browser.callJsFunction(
150150 createElementJs, tag.json, JsonObject (mutAttributes), id.json,
151- element.id.json, JsonPrimitive (insertBefore ? : " " ), JsonPrimitive (elementsCreatedCount)
151+ element.id.json, JsonPrimitive (insertBefore ? : " " ), JsonPrimitive (elementsCreatedCount), JsonPrimitive (namespace ? : " " )
152152 )
153153 }
154154 }
0 commit comments