In both the cases the output is identical as follows:
<?xml version="1.0" encoding="UTF-8"?>
<html itemscope="" itemtype="http://schema.org/QAPage" class="html__responsive">
<head>
<title>
java - Why doesn't HtmlUnitDriver execute JavaScript? - Stack Overflow
</title>
<link rel="shortcut icon" href="https://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico?v=4f32ecc8f43d"/>
<link rel="apple-touch-icon image_src" href="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a"/>
<link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml"/>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="https://stackoverflow.com/questions/7926246/why-doesnt-htmlunitdriver-execute-javascript"/>
<meta property="og:site_name" content="Stack Overflow"/>
<meta property="og:image" itemprop="image primaryImageOfPage" content="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded"/>
<meta name="twitter:card" content="summary"/>
<meta name="twitter:domain" content="stackoverflow.com"/>
<meta name="twitter:title" property="og:title" itemprop="title name" content="Why doesn't HtmlUnitDriver execute JavaScript?"/>
<meta name="twitter:description" property="og:description" itemprop="description" content="I got the following problem:
I am running a JUnit testCase with Selenium 2.9 using HtmlUnitDriver with Browserversion Firefox_3_6. JavaScript is enabled. Now when it should call and execute the fol..."/>
<script src="https://rules.quantcount.com/rules-p-c1rF4kxgLUzNc.js" async="">
</script>
<script async="" src="https://secure.quantserve.com/quant.js">
</script>
<script async="" src="https://sb.scorecardresearch.com/beacon.js">
</script>
<script async="" src="https://www.google-analytics.com/analytics.js">
</script>
<script src="https://pagead2.googlesyndication.com/pagead/osd.js">
</script>
<script src="https://cdn.ampproject.org/rtv/011811091519050/amp4ads-host-v0.js">
</script>
<script src="https://securepubads.g.doubleclick.net/gpt/pubads_impl_rendering_278.js?21062890">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>
<script src="https://cdn.sstatic.net/Js/stub.en.js?v=86fc07b77cb3">
</script>
<link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Shared/stacks.css?v=5023e4724ed5"/>
<link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/stackoverflow/primary-unified.css?v=9424d9dcf4a3"/>
<link rel="alternate" type="application/atom+xml" title="Feed for question 'Why doesn't HtmlUnitDriver execute JavaScript?'" href="/feeds/question/7926246"/>
<meta name="twitter:app:country" content="US"/>
<meta name="twitter:app:name:iphone" content="Stack Exchange iOS"/>
<meta name="twitter:app:id:iphone" content="871299723"/>
<meta name="twitter:app:url:iphone" content="se-zaphod://stackoverflow.com/questions/7926246/why-doesnt-htmlunitdriver-execute-javascript"/>
<meta name="twitter:app:name:ipad" content="Stack Exchange iOS"/>
<meta name="twitter:app:id:ipad" content="871299723"/>
<meta name="twitter:app:url:ipad" content="se-zaphod://stackoverflow.com/questions/7926246/why-doesnt-htmlunitdriver-execute-javascript"/>
<meta name="twitter:app:name:googleplay" content="Stack Exchange Android"/>
<meta name="twitter:app:url:googleplay" content="http://stackoverflow.com/questions/7926246/why-doesnt-htmlunitdriver-execute-javascript"/>
<meta name="twitter:app:id:googleplay" content="com.stackexchange.marvin"/>
<script>
//<![CDATA[
StackExchange.ready(function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.initSnippetRenderer();
});
StackExchange.using("postValidation", function () {
StackExchange.postValidation.initOnBlurAndSubmit($('#post-form'), 2, 'answer');
});
StackExchange.question.init({showAnswerHelp:true,totalCommentCount:2,shownCommentCount:2,highlightColor:'#F4A83D',backgroundColor:'#FFF',questionId:7926246});
styleCode();
StackExchange.realtime.subscribeToQuestion('1', '7926246');
StackExchange.using("gps", function () { StackExchange.gps.trackOutboundClicks('#content', '.post-text'); });
});
//]]>
</script>
<script>
//<![CDATA[
StackExchange.ready(function () {
var d = 100;
$.ajax({url:"https://cdn.sstatic.net/WinterBash/js/wb4qa.js?v=5",cache:true,dataType:"script"}).done(function tryInit() {
if (window.WinterBash) {
WinterBash.core.init('winterbash2018.stackexchange.com', 'https://cdn.sstatic.net/WinterBash/', '3', false);
} else {
if (d <= 800)
setTimeout(tryInit, d);
d *= 2;
}
});
});
//]]>
</script>
<script>
//<![CDATA[
StackExchange.init({"locale":"en","serverTime":1544623167,"routeName":"Questions/Show","stackAuthUrl":"https://stackauth.com","networkMetaHostname":"meta.stackexchange.com","site":{"name":"Stack Overflow","description":"Q&A for professional and enthusiast programmers","isNoticesTabEnabled":true,"enableNewTagCreationWarning":true,"insertSpaceAfterNameTabCompletion":false,"id":1,"childUrl":"https://meta.stackoverflow.com","enableSocialMediaInSharePopup":true,"protocol":"https"},"user":{"fkey":"29da02f0855a8cc9776a70151ea3e3d68966e60e54f9aa3b2491a5234ecba3cc","tid":"608f762a-97db-360f-08db-c52d8278395c","rep":0,"isAnonymous":true,"isAnonymousNetworkWide":true,"ab":{"inline_signup_hero":{"v":"d","g":1}}},"events":{"postType":{"question":1},"postEditionSection":{"title":1,"body":2,"tags":3}},"story":{"minCompleteBodyLength":75,"likedTagsMaxLength":300,"dislikedTagsMaxLength":300},"jobPreferences":{"maxNumDeveloperRoles":2,"maxNumIndustries":4},"svgIconPath":"https://cdn.sstatic.net/Img/svg-icons","svgIconHash":"38192da1e2db"}, {"site":{"allowImageUploads":true,"enableUserHovercards":true,"styleCode":true,"enableImgurHttps":true,"forceHttpsImages":true,"stacksValidation":true},"userMessaging":{},"comments":{},"userProfile":{"openGraphAPIKey":"58740831ad23540e00c58987"},"tags":{},"accounts":{"currentPasswordRequiredForChangingStackIdPassword":true},"flags":{"allowRetractingFlags":true},"snippets":{"snippetsEnabled":true,"renderDomain":"stacksnippets.net"},"paths":{},"markdown":{"asteriskIntraWordEmphasis":true},"monitoring":{"clientTimingsAbsoluteTimeout":30000,"clientTimingsDebounceTimeout":1000},"mentions":{"maxNumUsersInDropdown":50},"slack":{"sidebarAdDismissCookie":"slack-sidebar-ad"}});
StackExchange.using.setCacheBreakers({"js/prettify-full.en.js":"537577215963","js/moderator.en.js":"c48addfbc3c8","js/full-anon.en.js":"4dc78e89befa","js/full.en.js":"7b0d3adc4723","js/wmd.en.js":"942921cd6aa6","js/mobile.en.js":"0530e6d963ab","js/help.en.js":"ea9b6d3ca995","js/tageditor.en.js":"f5ffd857ba9d","js/tageditornew.en.js":"dbec77975b56","js/inline-tag-editing.en.js":"97b4a0d9f86f","js/revisions.en.js":"8f22ba768cac","js/review.en.js":"94323c3bdabd","js/tagsuggestions.en.js":"b278f9a0b23b","js/post-validation.en.js":"70b289599a70","js/explore-qlist.en.js":"222b04ca33bc","js/events.en.js":"dd2d0d0578a0","js/keyboard-shortcuts.en.js":"390ab347f2c4","js/external-editor.en.js":"cca27370f403","js/adops.en.js":"22a9bd59b1e9","js/begin-edit-event.en.js":"7415f5dee62d","js/external-editor.en.js":"cca27370f403","js/snippet-javascript.en.js":"ebc751779f44","js/snippet-javascript-codemirror.en.js":"fa05a6e17d62"});
StackExchange.using("gps", function() {
StackExchange.gps.init(true);
});
//]]>
</script>
<link rel="stylesheet" href="https://cdn.sstatic.net/clc/styles/clc.min.css?v=1db48f495ba1" type="text/css"/>
<link rel="preload" href="https://adservice.google.co.in/adsid/integrator.js?domain=stackoverflow.com"/>
<script type="text/javascript" src="https://adservice.google.co.in/adsid/integrator.js?domain=stackoverflow.com">
</script>
<link rel="preload" href="https://adservice.google.com/adsid/integrator.js?domain=stackoverflow.com"/>
<script type="text/javascript" src="https://adservice.google.com/adsid/integrator.js?domain=stackoverflow.com">
</script>
<script src="https://securepubads.g.doubleclick.net/gpt/pubads_impl_278.js?21062890" async="">
</script>
<link rel="prefetch" href="https://tpc.googlesyndication.com/safeframe/1-0-31/html/container.html"/>
<script async="" src="https://cdn.sstatic.net/Js/full-anon.en.js?v=4dc78e89befa">
</script>
<script async="" src="https://cdn.sstatic.net/Js/snippet-javascript.en.js?v=ebc751779f44">
</script>
<script async="" src="https://cdn.sstatic.net/Js/post-validation.en.js?v=70b289599a70">
</script>
<script async="" src="https://cdn.sstatic.net/Js/prettify-full.en.js?v=537577215963">
</script>
<script async="" src="https://cdn.sstatic.net/Js/external-editor.en.js?v=cca27370f403">
</script>
<link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/WinterBash/css/wb4qa.css?v=2"/>
</head>
<body class="question-page unified-theme">
<noscript id="noscript-css">
<style>body,.top-bar{margin-top:1.9em}</style>
</noscript>
<div id="notify-container">
</div>
<div id="custom-header">
</div>
<header class="top-bar js-top-bar top-bar__network _fixed">
<div class="-container">
<div class="-main">
<a href="#" class="left-sidebar-toggle p0 ai-center jc-center js-left-sidebar-toggle">
<span class="ps-relative">
</span>
</a>
<a href="https://stackoverflow.com" class="-logo js-gps-track" data-gps-track="top_nav.click({is_current:false, location:2, destination:8})">
<span class="-img _glyph">
Stack Overflow
</span>
</a>
</div>
<form id="search" action="/search" method="get" class="searchbar js-searchbar " autocomplete="off" role="search">
<div class="ps-relative">
<input name="q" type="text" placeholder="Search…" value="" autocomplete="off" maxlength="240" class="f-input js-search-field "/>
<button type="submit" aria-label="Search..." class="s-btn s-btn__primary btn-topbar-primary js-search-submit">
<svg aria-hidden="true" class="svg-icon iconSearch" width="18" height="18" viewbox="0 0 18 18">
<path d="M12.86 11.32L18 16.5 16.5 18l-5.18-5.14v-.35a7 7 0 1 1 1.19-1.19h.35zM7 12A5 5 0 1 0 7 2a5 5 0 0 0 0 10z"/>
</svg>
</button>
</div>
</form>
<ol class="-secondary js-secondary-topbar-links drop-icons-responsively the-js-is-handling-responsiveness">
<li class="-item searchbar-trigger js-searchbar-trigger">
<a href="#" class="-link">
<svg aria-hidden="true" class="svg-icon iconSearch" width="18" height="18" viewbox="0 0 18 18">
<path d="M12.86 11.32L18 16.5 16.5 18l-5.18-5.14v-.35a7 7 0 1 1 1.19-1.19h.35zM7 12A5 5 0 1 0 7 2a5 5 0 0 0 0 10z"/>
</svg>
</a>
</li>
<li class="-item">
<a href="https://stackexchange.com/users/?tab=inbox" class="-link js-inbox-button" title="Recent inbox messages">
<svg aria-hidden="true" class="svg-icon iconInbox" width="20" height="18" viewbox="0 0 20 18">
<path d="M15.19 1H4.63c-.85 0-1.6.54-1.85 1.35L0 10.79V15c0 1.1.9 2 2 2h16a2 2 0 0 0 2-2v-4.21l-2.87-8.44A2 2 0 0 0 15.19 1zm-.28 10l-2 2h-6l-2-2H1.96L4.4 3.68A1 1 0 0 1 5.35 3h9.12a1 1 0 0 1 .95.68L17.86 11h-2.95z"/>
</svg>
<span class="indicator-badge js-unread-count _important" style="display: none;">
</span>
</a>
</li>
<li class="-item">
<a href="https://stackexchange.com/users/?tab=reputation" class="-link js-achievements-button" title="Recent achievements: reputation, badges, and privileges earned" data-unread-class="_highlighted-positive">
<svg aria-hidden="true" class="svg-icon iconAchievements" width="18" height="18" viewbox="0 0 18 18">
<path d="M15 2V1H3v1H0v4c0 1.6 1.4 3 3 3v1c.4 1.5 3 2.6 5 3v2H5s-1 1.5-1 2h10c0-.4-1-2-1-2h-3v-2c2-.4 4.6-1.5 5-3V9c1.6-.2 3-1.4 3-3V2h-3zM3 7c-.5 0-1-.5-1-1V4h1v3zm8.4 2.5L9 8 6.6 9.4l1-2.7L5 5h3l1-2.7L10 5h2.8l-2.3 1.8 1 2.7h-.1zM16 6c0 .5-.5 1-1 1V4h1v2z"/>
</svg>
<span class="indicator-badge js-unread-count _positive" style="display: none;">
</span>
</a>
</li>
<li class="-item help-button-item" data-remove-order="1">
<a href="#" class="-link js-help-button" title="Help Center and other resources">
<svg aria-hidden="true" class="svg-icon iconHelp" width="18" height="18" viewbox="0 0 18 18">
<path d="M9 1a8 8 0 1 0 0 16A8 8 0 0 0 9 1zm.81 12.13c-.02.71-.55 1.15-1.24 1.13-.66-.02-1.17-.49-1.15-1.2.02-.72.56-1.18 1.22-1.16.7.03 1.2.51 1.17 1.23zM11.77 8a5.8 5.8 0 0 1-1.02.91l-.53.37c-.26.2-.42.43-.5.69a4 4 0 0 0-.09.75c0 .05-.03.16-.18.16H7.88c-.16 0-.18-.1-.18-.15.03-.66.12-1.21.4-1.66a5.29 5.29 0 0 1 1.43-1.22c.16-.12.28-.25.38-.39a1.34 1.34 0 0 0 .02-1.71c-.24-.31-.51-.46-1.03-.46-.51 0-.8.26-1.02.6-.21.33-.18.73-.18 1.1H5.75c0-1.38.35-2.25 1.1-2.76.52-.35 1.17-.5 1.93-.5 1 0 1.79.18 2.49.71.64.5.98 1.18.98 2.12 0 .57-.2 1.05-.48 1.44z"/>
</svg>
</a>
</li>
<li class="-item site-switcher-item">
<a href="https://stackexchange.com" class="-link js-site-switcher-button js-gps-track" data-gps-track="site_switcher.show" title="A list of all 174 Stack Exchange sites">
<svg aria-hidden="true" class="svg-icon iconStackExchange" width="18" height="18" viewbox="0 0 18 18">
<path d="M1 13c0 1.1.9 2 2 2h8v3l3-3h1a2 2 0 0 0 2-2v-2H1v2zM15 1H3a2 2 0 0 0-2 2v2h16V3a2 2 0 0 0-2-2zM1 6h16v4H1V6z"/>
</svg>
</a>
</li>
<li class="-ctas">
<a href="https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f7926246%2fwhy-doesnt-htmlunitdriver-execute-javascript" class="login-link s-btn btn-topbar-clear py8" rel="nofollow">
Log In
</a>
<a href="https://stackoverflow.com/users/signup?ssrc=head&returnurl=%2fusers%2fstory%2fcurrent" class="login-link s-btn s-btn__primary py8 btn-topbar-primary" rel="nofollow" data-ga="["sign up","Sign Up Navigation","Header",null,null]">
Sign Up
</a>
</li>
<li class="-dialog-container js-topbar-dialog-corral">
<div class="topbar-dialog siteSwitcher-dialog dno">
<div class="header">
<h3>
<a href="https://stackoverflow.com">
current community
</a>
</h3>
</div>
<div class="modal-content current-site-container">
<ul class="current-site">
<li class="grid">
<div class="fl1">
<a href="https://stackoverflow.com" class="current-site-link site-link js-gps-track grid gs8 gsx" data-id="1" data-gps-track="site_switcher.click({ item_type:3 })">
<div class="favicon favicon-stackoverflow site-icon grid--cell" title="Stack Overflow">
</div>
<span class="grid--cell fl1">
Stack Overflow
</span>
</a>
</div>
<div class="related-links">
<a href="https://stackoverflow.com/help" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:14 })">
help
</a>
<a href="https://chat.stackoverflow.com" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:6 })">
chat
</a>
</div>
</li>
<li class="related-site grid">
<div class="L-shaped-icon-container">
<span class="L-shaped-icon">
</span>
</div>
<a href="https://meta.stackoverflow.com" class="site-link js-gps-track grid gs8 gsx" data-id="552" data-gps-track="site.switch({ target_site:552, item_type:3 }),site_switcher.click({ item_type:4 })">
<div class="favicon favicon-stackoverflowmeta site-icon grid--cell" title="Meta Stack Overflow">
</div>
<span class="grid--cell fl1">
Meta Stack Overflow
</span>
</a>
</li>
</ul>
</div>
<div class="header" id="your-communities-header">
<h3>
your communities
</h3>
</div>
<div class="modal-content" id="your-communities-section">
<div class="call-to-login">
<a href="https://stackoverflow.com/users/signup?ssrc=site_switcher&returnurl=%2fusers%2fstory%2fcurrent" class="login-link js-gps-track" data-gps-track="site_switcher.click({ item_type:10 })">
Sign up
</a>
or
<a href="https://stackoverflow.com/users/login?ssrc=site_switcher&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f7926246%2fwhy-doesnt-htmlunitdriver-execute-javascript" class="login-link js-gps-track" data-gps-track="site_switcher.click({ item_type:11 })">
log in
</a>
to customize your list.
</div>
</div>
<div class="header">
<h3>
<a href="https://stackexchange.com/sites">
more stack exchange communities
</a>
</h3>
<a href="https://stackoverflow.blog" class="fr">
company blog
</a>
</div>
<div class="modal-content">
<div class="child-content">
</div>
</div>
</div>
<div class="topbar-dialog help-dialog js-help-dialog dno">
<div class="modal-content">
<ul>
<li>
<a href="/tour" class="js-gps-track" data-gps-track="help_popup.click({ item_type:1 })">
.
.
.
getLoadingState
</span>
<span class="pun">
();
</span>
<span class="pln">
</span>
<span class="pun">
}
</span>
</code>
</pre>
<p>
I want to get to ABC.do
</p>
<p>
If I execute my test with the FirefoxDriver it works.
</p>
<p>
Is there a way to get this working with HtmlUnitDriver?
My test works if I manually call driver.get("
<a href="http://host/ABC.do" rel="noreferrer">
http://host/ABC.do
</a>
") but that cannot be the right way to do this.
</p>
</div>
<div class="post-taglist grid gs4 gsy fd-column">
<div class="grid ps-relative d-block">
<a href="/questions/tagged/java" class="post-tag js-gps-track" title="show questions tagged 'java'" rel="tag">
java
</a>
<a href="/questions/tagged/javascript" class="post-tag js-gps-track" title="show questions tagged 'javascript'" rel="tag">
javascript
</a>
<a href="/questions/tagged/ajax" class="post-tag js-gps-track" title="show questions tagged 'ajax'" rel="tag">
ajax
</a>
<a href="/questions/tagged/selenium" class="post-tag js-gps-track" title="show questions tagged 'selenium'" rel="tag">
selenium
</a>
<a href="/questions/tagged/htmlunit-driver" class="post-tag js-gps-track" title="show questions tagged 'htmlunit-driver'" rel="tag">
htmlunit-driver
</a>
</div>
</div>
<div class="mb0 ">
<div class="mt16 pt4 grid gs8 gsy fw-wrap jc-end ai-start">
<div class="grid--cell mr16" style="flex: 1 1 100px;">
<div class="post-menu">
<a href="/q/7926246" title="short permalink to this question" class="short-link" id="link-post-7926246">
share
</a>
<span class="lsep">
|
</span>
<a href="/posts/7926246/edit" class="suggest-edit-post" title="">
improve this question
</a>
</div>
</div>
<div class="post-signature grid--cell">
<div class="user-info user-hover">
<div class="user-action-time">
<a href="/posts/7926246/revisions" title="show all edits to this post">
edited
<span title="2016-03-31 13:31:33Z" class="relativetime">
Mar 31 '16 at 13:31
</span>
</a>
</div>
<div class="user-gravatar32">
<a href="/users/759866/benjamin">
<div class="gravatar-wrapper-32">
<img src="https://www.gravatar.com/avatar/cc21bd143a63dbea51c2caa5f1e8599b?s=32&d=identicon&r=PG" alt="" width="32" height="32"/>
</div>
</a>
</div>
<div class="user-details">
<a href="/users/759866/benjamin">
Benjamin
</a>
<div class="-flair">
<span class="reputation-score" title="reputation score 15,789" dir="ltr">
15.8k
</span>
<span title="28 gold badges">
<span class="badge1">
</span>
<span class="badgecount">
28
</span>
</span>
<span title="119 silver badges">
<span class="badge2">
</span>
<span class="badgecount">
119
</span>
</span>
<span title="230 bronze badges">
<span class="badge3">
</span>
<span class="badgecount">
230
</span>
</span>
</div>
</div>
</div>
</div>
<div class="post-signature owner grid--cell">
<div class="user-info ">
<div class="user-action-time">
.
.
.
</script>
<noscript>
<div id="noscript-warning">Stack Overflow works best with JavaScript enabled
<img src="https://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif" alt="" class="dno">
</div>
</noscript>
<script>
//<![CDATA[
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m);
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
StackExchange.ready(function () {
StackExchange.ga.init({
sendTitles: true,
tracker: window.ga,
trackingCodes: [
'UA-108242619-1'
]
});
StackExchange.ga.setDimension('dimension2', '|java|javascript|ajax|selenium|htmlunit-driver|');
StackExchange.ga.setDimension('dimension3', 'Questions/Show');
StackExchange.ga.trackPageView();
});
/**/
var _qevents = _qevents || [],
_comscore = _comscore || [];
(function() {
var ssl = 'https:' == document.location.protocol,
s = document.getElementsByTagName('script')[0],
qc = document.createElement('script');
qc.async = true;
qc.src = (ssl ? 'https://secure' : 'http://edge') + '.quantserve.com/quant.js';
s.parentNode.insertBefore(qc, s);
_qevents.push({ qacct: "p-c1rF4kxgLUzNc" });
/**/
var sc = document.createElement('script');
sc.async = true;
sc.src = (ssl ? 'https://sb' : 'http://b') + '.scorecardresearch.com/beacon.js';
s.parentNode.insertBefore(sc, s);
_comscore.push({ c1: "2", c2: "17440561" });
})();
//]]>
</script>
</body>
</html>