Can't click on a youtube AJAX link with HtmlUnit
I'm trying to use htmlunit to click on a link in youtube. Here's the code:
HtmlPage page = webClient.getPage("http://www.youtube.com");
HtmlAnchor link = page.getFirstByXPath("//a[contains(@href, 'accounts/ServiceLogin?')]");
page = link.click();
HtmlForm form = page.getFirstByXPath("//form[@id='gaia_loginform']");
form.getInputByName("Email")开发者_开发百科.setValueAttribute("login");
form.getInputByName("Passwd").setValueAttribute("pass");
page = form.getInputByName("signIn").click();
page = webClient.getPage("http://www.youtube.com/watch?v=_cLaKr1j55w");
page.getElementById("watch-tab-favorite").click();
but it doesn't work :( The code of the element I'm trying to click is
<div id="watch-tab-favorite" class="watch-tab" onclick="if (!_hasclass(this, 'disabled')) { yt.www.watch.favorites.add('addToFavesForm'); }">
I've also tried page.executeJavaScript("yt.www.watch.favorites.add('addToFavesForm');");
with no success either. Seems like htmlunit isn't sending the request at all. How can I fix it? TIA
Have a look at http://htmlunit.sourceforge.net/faq.html#AJAXDoesNotWork
Otherwise, please use HtmlUnit user list
精彩评论