Skip to content

[🐛 Bug]: JavascriptError occurs when executing WebElement.getAttribute('value'), WebElement.isDisplayed(), or WebElement.submit() in Edge/IE mode on pages with document mode 7 or lower #16618

@yusuke-noda

Description

@yusuke-noda

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.

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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!C-nodejsJavaScript BindingsD-IEG-msedgedriverRequires fixes in MSEdgeDriverI-defectSomething is not working as intendedI-regressionSomething was working but we "fixed" itOS-windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions