-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Description
Description
When executing WebElement.getAttribute('value') in Edge's IE mode on a page with document mode 7 or lower, the following error occurs.
This error also occurs when executing WebElement.isDisplayed().
JavascriptError: Error from JavaScript: 'HTMLFormElement' is undefined
at Object.throwDecodedError (C:\myproject\node_modules\selenium-webdriver\lib\error.js:523:15)
at parseHttpResponse (C:\myproject\node_modules\selenium-webdriver\lib\http.js:524:13)
at Executor.execute (C:\myproject\node_modules\selenium-webdriver\lib\http.js:456:28)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Driver.execute (C:\myproject\node_modules\selenium-webdriver\lib\webdriver.js:745:17)
at async C:\myproject\test.js:11:19 {
remoteStacktrace: ''
}
Also, when executing WebDriver.submit() in Edge's IE mode on a page with document mode 8 or lower, a similar error occurs.
JavascriptError: Error from JavaScript: Object doesn't support property or method 'createEvent'
at Object.throwDecodedError (C:\myproject\node_modules\selenium-webdriver\lib\error.js:523:15)
at parseHttpResponse (C:\myproject\node_modules\selenium-webdriver\lib\http.js:524:13)
at Executor.execute (C:\myproject\node_modules\selenium-webdriver\lib\http.js:456:28)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Driver.execute (C:\myproject\node_modules\selenium-webdriver\lib\webdriver.js:745:17)
at async C:\myproject\test.js:11:5 {
remoteStacktrace: ''
}
Reproducible Code
test.js
const { Builder, Browser, By } = require('selenium-webdriver');
(async () => {
let driver;
try {
driver = await new Builder().forBrowser(Browser.INTERNET_EXPLORER)
.setIeOptions({'se:ieOptions': { 'ie.edgechronium': true }})
.build();
await driver.get('http://localhost:4000/ie5.html'); // this page is documentMode 5
const elm = driver.findElement(By.css('input'));
const value = await elm.getAttribute('value');
console.log(value);
} catch (e) {
console.log(e)
} finally {
await driver.quit();
}
})();
ie5.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=5">
<title>ie5</title>
</head>
<body>
<form>
<input type="text" value="foo">
</form>
</body>
</html>The following code is causing this bug.
In IE with document mode 7 or lower, an error occurs because HTMLFormElement is undefined.
selenium/javascript/atoms/domcore.js
Lines 166 to 178 in e0afdd3
| bot.dom.core.isElement = function (node, opt_tagName) { | |
| // because we call this with deprecated tags such as SHADOW | |
| if (opt_tagName && (typeof opt_tagName !== 'string')) { | |
| opt_tagName = opt_tagName.toString(); | |
| } | |
| // because node.tagName.toUpperCase() fails when tagName is "tagName" | |
| if (node instanceof HTMLFormElement) { | |
| return !!node && node.nodeType == goog.dom.NodeType.ELEMENT && | |
| (!opt_tagName || "FORM" == opt_tagName); | |
| } | |
| return !!node && node.nodeType == goog.dom.NodeType.ELEMENT && | |
| (!opt_tagName || node.tagName.toUpperCase() == opt_tagName); | |
| }; |
For submit() issue, this is because document.createEvent is undefined in document mode 8 and below.
selenium/javascript/selenium-webdriver/lib/webdriver.js
Lines 2960 to 2973
in
e0afdd3
submit() {
const script =
'/* submitForm */var form = arguments[0];\n' +
'while (form.nodeName != "FORM" && form.parentNode) {\n' +
' form = form.parentNode;\n' +
'}\n' +
"if (!form) { throw Error('Unable to find containing form element'); }\n" +
"if (!form.ownerDocument) { throw Error('Unable to find owning document'); }\n" +
"var e = form.ownerDocument.createEvent('Event');\n" +
"e.initEvent('submit', true, true);\n" +
'if (form.dispatchEvent(e)) { HTMLFormElement.prototype.submit.call(form) }\n'
return this.driver_.executeScript(script, this)
}
selenium/javascript/selenium-webdriver/lib/webdriver.js
Lines 2960 to 2973 in e0afdd3
| submit() { | |
| const script = | |
| '/* submitForm */var form = arguments[0];\n' + | |
| 'while (form.nodeName != "FORM" && form.parentNode) {\n' + | |
| ' form = form.parentNode;\n' + | |
| '}\n' + | |
| "if (!form) { throw Error('Unable to find containing form element'); }\n" + | |
| "if (!form.ownerDocument) { throw Error('Unable to find owning document'); }\n" + | |
| "var e = form.ownerDocument.createEvent('Event');\n" + | |
| "e.initEvent('submit', true, true);\n" + | |
| 'if (form.dispatchEvent(e)) { HTMLFormElement.prototype.submit.call(form) }\n' | |
| return this.driver_.executeScript(script, this) | |
| } |
ℹ️ Last known working version: 3.6.0