views:

257

answers:

1

Hello, 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

+1  A: 

Have a look at http://htmlunit.sourceforge.net/faq.html#AJAXDoesNotWork

Otherwise, please use HtmlUnit user list

Ahmed Ashour