I have code for open bootstrap remote modal:
function showModal(url) {
$('body').append('<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"></div></div></div>');
var modal = $('#modal');
modal.on('hidden.bs.modal', function() {
$(this).remove();
});
modal.modal({
show: true,
remote: encodeURI(url)
});
return modal;
}
This opens remote modal correctly with:
<a id="mdl" onclick="showModal('http://localhost/modal1.php')">Open</a>
modal1.php:
<div>Modal!!!</div>
Now I want to test it in HtmlUnit. So I wrote
WebClient web = new WebClient();
HtmlPage page = (HtmlPage) mWebClient.getPage("http://localhost/");
page = (HtmlPage)((HtmlAnchore)page.getDocumentElement().querySelector("#mdl")).click();
Now the problem is that the content is unreachable.
page.getDocumentElement().querySelector(".modal .modal-content"); // Return object
page.getDocumentElement().querySelector(".modal .modal-content div"); // Return null
Its looks like that the page doesn't get the elements from the AJAX call. (In real browser its works)
I tried:
web.waitForBackgroundJavaScript(100000);
web.waitForBackgroundJavaScriptStartingBefore(10000)
web.setAjaxController(new AjaxController() {
@Override
public boolean processSynchron(HtmlPage page, WebRequest request, boolean async) {
return true;
}
});
And it still not working...
It is like the $.load
function not working in HtmlUnit.
How can I check the content with HtmlUnit?