I have a basic webpage featuring a button that triggers a Bootstrap modal. However, even though the modal pops up, I can't seem to interact with the button inside the modal.
I've attempted three different approaches to tackle this issue: 1) trying to directly locate the element, 2) locating the element through the modal element itself, and 3) using an explicit wait. Unfortunately, all three methods result in the same error - ElementNotInteractableError: element not interactable.
While it's possible that this problem has been addressed elsewhere on Stack Overflow (which is why I tried multiple approaches), none of the solutions provided there were able to help me.
Here is the error stack trace:
DevTools listening on ws://127.0.0.1:50284/devtools/browser/1a87603d-af78-486d-bc37-161eeeed16ba [5396:11184:0428/110516.874:ERROR:browser_switcher_service.cc(238)] XXX Init() ElementNotInteractableError: element not interactable (Session info: chrome=81.0.4044.122) at Object.throwDecodedError (D:\ip300-gk\node_modules\selenium-webdriver\lib\error.js:550:15) at parseHttpResponse (D:\ip300-gk\node_modules\selenium-webdriver\lib\http.js:565:13) at Executor.execute (D:\ip300-gk\node_modules\selenium-webdriver\lib\http.js:491:26) at processTicksAndRejections (internal/process/task_queues.js:93:5) at async Driver.execute (D:\ip300-gk\node_modules\selenium-webdriver\lib\webdriver.js:700:17) at async uitest (D:\ip300-gk\Samples\bootstrap\bs-modal-selenium\uitest.js:26:11) { name: 'ElementNotInteractableError',
Below is the JavaScript test code where all three approaches were attempted:
const driver = require('selenium-webdriver')
const assert = require('assert').strict;
const {Builder, By, Key, until} = require('selenium-webdriver');
let fileName = "D:\\ip300-gk\\Samples\\bootstrap\\bs-modal-selenium\\index.html"
uitest()
async function uitest() {
let driver = await new Builder().forBrowser('chrome').build();
let modal, element
try {
await driver.get(fileName)
await driver.findElement(By.id('launchModalButton')).click()
// approach 1 - getting error - ElementNotInteractableError: element not interactable
// await driver.findElement(By.id('saveChangesButton')).click()
// approach 2 using explicit wait - getting error - ElementNotInteractableError: element not interactable
element = await driver.wait(until.elementLocated(By.id('saveChangesButton')))
await element.click()
// approach 3 - finding modal using root modal - getting error - //ElementNotInteractableError: element not interactable
// modal = await driver.findElement(By.id('exampleModal'))
// await modal.findElement(By.id('saveChangesButton')).click()
} catch (err) {
console.log(err)
} finally {
await driver.quit();
}
}
This is the HTML code for the Bootstrap page:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<title>Selenium </title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
<div class="container">
<button type="button" id="launchModalButton" class="btn btn-primary mt-5" data-toggle="modal" data-target="#exampleModal">
Launch modal
</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Sample Modal
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button id="saveChangesButton" type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>