[prev in list] [next in list] [prev in thread] [next in thread] 

List:       htmlunit-user
Subject:    Re: [Htmlunit-user] facebook login
From:       Ahmed Ashour <asashour () yahoo ! com>
Date:       2009-12-16 5:11:51
Message-ID: 237572.96143.qm () web112212 ! mail ! gq1 ! yahoo ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Sander,

Public sites like facebook changes frequently.

By default, HtmlUnit fail with any JS error (just like real browsers), you can \
configure that with webClient.setThrowExceptionOnScriptError(false), however the \
website may not work correctly in this case.

Regarding the below case, the API was incorrectly used:

In the source of facebook login:

                   <form method="POST" action="..." id="login_form" onsubmit="...">

This can be accessed by:

                  page.getElementById("login_form")

Not by:

                  page.getFormByName("login_form");

Because the form does not have a name.


Ahmed----
Blog: http://asashour.blogspot.com 

________________________________
From: Sander A. Smith <smithsa@sericontech.com>
To: htmlunit-user@lists.sourceforge.net
Sent: Tue, December 15, 2009 10:11:31 PM
Subject: Re: [Htmlunit-user] facebook login


Okay, I'm a bit confused here, maybe someone can clue me in.

My understanding was that Htmlunit has a problem with Facebook because the JavaScript \
that Facebook uses is known to be problematic. The browsers are able to deal with \
this, but Htmlunit can't. Of course, it's open source built by volunteers, so I'll \
give you guys some slack and appreciate all of the stuff that DOES work.

But now it sounds like things may work depending on how the HTML elements are \
addressed. Access them one way and things fail, but if you use XPath they work. Seems \
to me that this is competely separate from any JavaScript issues - what's going on?

Sander


On Tue, Dec 15, 2009 at 9:15 AM, Ahmed Ashour <asashour@yahoo.com> wrote:


> Great news.
> 
> 
> 
> 
> ihavealegohead wrote:
> > 
> > 
> > 
> > ihavealegohead wrote:
> > > 
> > > I am testing htmlunit with facebook.  I try a login, but fails:
> > > 
> > > run:
> > > Dec 14, 2009 5:50:12 PM
> > > com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
> > > WARNING: Expected content type of 'application/javascript' or
> > > 'application/ecmascript' for remotely loaded JavaScript element at
> > > 'http://b.static.ak.fbcdn.net/rsrc.php/zCOXE/hash/dbni8t78.js', but got
> > > 'application/x-javascript'.
> > > Exception in thread "main"
> > > com.gargoylesoftware.htmlunit.ElementNotFoundException:
> > > elementName=[form] attributeName=[name] attributeValue=[login_form]
> > > at
> > > com.gargoylesoftware.htmlunit.html.HtmlPage.getFormByName(HtmlPage.java:588)
> > > at fblogin.Main.main(Main.java:36)
> > > Java Result: 1
> > > BUILD SUCCESSFUL (total time: 10 seconds)
> > > 
> > > 
> > > Indeed, the login form attribute is login_form:
> > > 
> > > <form method="POST"
> > > action="https://login.facebook.com/login.php?login_attempt=1"
> > > id="login_form">
> > > 
> > > Here is my source:
> > > 
> > > package fblogin;
> > > import java.io.IOException;
> > > import java.net.URL;
> > > 
> > > import com.gargoylesoftware.htmlunit.BrowserVersion;
> > > import com.gargoylesoftware.htmlunit.Page;
> > > import com.gargoylesoftware.htmlunit.RefreshHandler;
> > > import com.gargoylesoftware.htmlunit.WebClient;
> > > import com.gargoylesoftware.htmlunit.html.HtmlForm;
> > > import com.gargoylesoftware.htmlunit.html.HtmlPage;
> > > 
> > > 
> > > 
> > > /**
> > > *
> > > * @author me
> > > */
> > > public class Main {
> > > 
> > > /**
> > > * @param args the command line arguments
> > > */
> > > public static void main(String[] args) throws Exception {
> > > // Create and initialize WebClient object
> > > WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);
> > > webClient.setThrowExceptionOnScriptError(false);
> > > webClient.setRefreshHandler(new RefreshHandler() {
> > > public void handleRefresh(Page page, URL url, int arg) throws
> > > IOException {
> > > System.out.println("handleRefresh");
> > > }
> > > 
> > > });
> > > // visit Facebook login page and get the Form object
> > > 
> > > HtmlPage page = (HtmlPage)
> > > webClient.getPage("http://www.facebook.com/login.php");
> > > HtmlForm form = page.getFormByName("login_form");
> > > 
> > > // Enter login and passwd
> > > form.getInputByName("email").setValueAttribute("me@email.com");
> > > form.getInputByName("pass").setValueAttribute("PASS");
> > > // Click "Login" button/link
> > > page = (HtmlPage) form.getInputByValue("Login").click();
> > > 
> > > }
> > > }
> > > 
> > > 
> > > Any idea how I messed this up?
> > > 
> > 
> > 
> > I wasn't able to get that code to work, so I switched it to Xpath:
> > 
> > HtmlForm form =
> > page.getFirstByXPath(".//*[@id='login_form']");
> 
> > form.getInputByName("email").setValueAttribute("me@email.com");
> > form.getInputByName("pass").setValueAttribute("pass");
> 
> > page = (HtmlPage) form.getInputByValue("Login").click();
> > 
> > 
> > -Thank You-
> > 
> > 
> > 
> 
> --
> View this message in context: \
> http://old.nabble.com/facebook-login-tp26780472p26795475.html 
> Sent from the HtmlUnit - General mailing list archive at Nabble.com.
> 
> 
> ------------------------------------------------------------------------------
> Return on Information:
> Google Enterprise Search pays you back
> Get the facts.
> http://p.sf.net/sfu/google-dev2dev
> _______________________________________________
> Htmlunit-user mailing list
> Htmlunit-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/htmlunit-user
> 


-- 
Sander A. Smith
President

Sericon Technology Inc.
71 Marquette Ave.
Toronto, Ontario M6A 1X8
(416)781-3988

Link to me on LinkedIn
http://www.linkedin.com/in/sandersmith

Join our community of people interested in testing Facebook applications
http://www.TestFacebook.com

Learn about advanced tools for testing social networking applications
http://www.FriendRunner.com

http://www.sericontech.com



      


[Attachment #5 (text/html)]

<html><head><style type="text/css"><!-- DIV {margin:0px;} \
--></style></head><body><div style="font-family:times new roman, new york, times, \
serif;font-size:12pt"><DIV></DIV> <DIV>Hi Sander,</DIV>
<DIV>&nbsp;</DIV>
<DIV>Public sites like facebook changes frequently.</DIV>
<DIV>&nbsp;</DIV>
<DIV>By default, HtmlUnit fail with any JS error (just like real browsers),&nbsp;you \
can configure that with webClient.setThrowExceptionOnScriptError(false), \
however&nbsp;the website may not work correctly in this case.</DIV> <DIV>&nbsp;</DIV>
<DIV>Regarding the below case, the API was incorrectly used:</DIV>
<DIV>&nbsp;</DIV>
<DIV>In the source of facebook login:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
&lt;form method="POST" action="..." <FONT color=#ff0000>id</FONT>="login_form" \
onsubmit="..."&gt;</DIV> <DIV>&nbsp;</DIV>
<DIV>This&nbsp;can be accessed by:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.getElementById("login_form")</DIV>
 <DIV>&nbsp;</DIV>
<DIV>Not by:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.getFormByName("login_form");</DIV>
 <DIV>&nbsp;</DIV>
<DIV>Because the form does not have a name.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Ahmed</DIV>----<BR>Blog: http://asashour.blogspot.com
<DIV><FONT size=2 face=Tahoma>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Sander A. Smith \
&lt;smithsa@sericontech.com&gt;<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> \
htmlunit-user@lists.sourceforge.net<BR><B><SPAN style="FONT-WEIGHT: \
bold">Sent:</SPAN></B> Tue, December 15, 2009 10:11:31 PM<BR><B><SPAN \
style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [Htmlunit-user] facebook \
login<BR></FONT><BR></DIV> <DIV style="FONT-FAMILY: times new roman, new york, times, \
serif; FONT-SIZE: 12pt"> <DIV style="FONT-FAMILY: times new roman, new york, times, \
serif; FONT-SIZE: 12pt"> <DIV>Okay, I'm a bit confused here, maybe someone can clue \
me in.</DIV> <DIV>&nbsp;</DIV>
<DIV>My understanding was that Htmlunit has a problem with Facebook because the \
JavaScript that Facebook uses is known to be problematic. The browsers are able to \
deal with this, but Htmlunit can't. Of course, it's open source&nbsp;built by \
volunteers, so I'll give you guys some slack and appreciate all of the stuff that \
DOES work.</DIV> <DIV>&nbsp;</DIV>
<DIV>But now it sounds like things may work depending on how the HTML elements are \
addressed. Access them one way and things fail, but if you use XPath they work. Seems \
to me that this is competely separate from any JavaScript issues - what's going \
on?</DIV> <DIV>&nbsp;</DIV>
<DIV>Sander<BR><BR></DIV>
<DIV class=gmail_quote>On Tue, Dec 15, 2009 at 9:15 AM, Ahmed Ashour <SPAN \
dir=ltr>&lt;<A href="mailto:asashour@yahoo.com" rel=nofollow target=_blank \
ymailto="mailto:asashour@yahoo.com">asashour@yahoo.com</A>&gt;</SPAN> wrote:<BR> \
<BLOCKQUOTE style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; \
PADDING-LEFT: 1ex" class=gmail_quote><BR>Great news.<BR> <DIV>
<DIV></DIV>
<DIV class=h5><BR><BR><BR>ihavealegohead wrote:<BR>&gt;<BR>&gt;<BR>&gt;<BR>&gt; \
ihavealegohead wrote:<BR>&gt;&gt;<BR>&gt;&gt; I am testing htmlunit with facebook. \
&nbsp;I try a login, but fails:<BR>&gt;&gt;<BR>&gt;&gt; run:<BR>&gt;&gt; Dec 14, 2009 \
5:50:12 PM<BR>&gt;&gt; com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl \
notify<BR>&gt;&gt; WARNING: Expected content type of 'application/javascript' \
or<BR>&gt;&gt; 'application/ecmascript' for remotely loaded JavaScript element \
at<BR>&gt;&gt; 'http://b.static.ak.fbcdn.net/rsrc.php/zCOXE/hash/dbni8t78.js', but \
got<BR>&gt;&gt; 'application/x-javascript'.<BR>&gt;&gt; Exception in thread \
"main"<BR>&gt;&gt; com.gargoylesoftware.htmlunit.ElementNotFoundException:<BR>&gt;&gt; \
elementName=[form] attributeName=[name] attributeValue=[login_form]<BR>&gt;&gt; \
&nbsp; &nbsp; &nbsp; &nbsp; at<BR>&gt;&gt; \
com.gargoylesoftware.htmlunit.html.HtmlPage.getFormByName(HtmlPage.java:588)<BR>&gt;&gt; \
&nbsp; &nbsp; &nbsp;  &nbsp; at fblogin.Main.main(Main.java:36)<BR>&gt;&gt; Java \
Result: 1<BR>&gt;&gt; BUILD SUCCESSFUL (total time: 10 \
seconds)<BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;&gt; Indeed, the login form attribute is \
login_form:<BR>&gt;&gt;<BR>&gt;&gt; &lt;form method="POST"<BR>&gt;&gt; action="<A \
href="https://login.facebook.com/login.php?login_attempt=1" rel=nofollow \
target=_blank>https://login.facebook.com/login.php?login_attempt=1</A>"<BR>&gt;&gt; \
id="login_form"&gt;<BR>&gt;&gt;<BR>&gt;&gt; Here is my \
source:<BR>&gt;&gt;<BR>&gt;&gt; package fblogin;<BR>&gt;&gt; import <A \
href="http://java.io.io/" target=_blank>java.io</A>.IOException;<BR>&gt;&gt; import \
<A href="http://java.net/" target=_blank>java.net</A>.URL;<BR>&gt;&gt;<BR>&gt;&gt; \
import com.gargoylesoftware.htmlunit.BrowserVersion;<BR>&gt;&gt; import \
com.gargoylesoftware.htmlunit.Page;<BR>&gt;&gt; import \
com.gargoylesoftware.htmlunit.RefreshHandler;<BR>&gt;&gt; import  \
com.gargoylesoftware.htmlunit.WebClient;<BR>&gt;&gt; import \
com.gargoylesoftware.htmlunit.html.HtmlForm;<BR>&gt;&gt; import \
com.gargoylesoftware.htmlunit.html.HtmlPage;<BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;&gt; \
/**<BR>&gt;&gt; &nbsp;*<BR>&gt;&gt; &nbsp;* @author me<BR>&gt;&gt; \
&nbsp;*/<BR>&gt;&gt; public class Main {<BR>&gt;&gt;<BR>&gt;&gt; &nbsp; &nbsp; \
/**<BR>&gt;&gt; &nbsp; &nbsp; &nbsp;* @param args the command line \
arguments<BR>&gt;&gt; &nbsp; &nbsp; &nbsp;*/<BR>&gt;&gt; &nbsp; &nbsp; public static \
void main(String[] args) throws Exception {<BR>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; \
// Create and initialize WebClient object<BR>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp;WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);<BR>&gt;&gt; \
&nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp;webClient.setThrowExceptionOnScriptError(false);<BR>&gt;&gt; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp;webClient.setRefreshHandler(new RefreshHandler() {<BR>&gt;&gt; \
&nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public \
void handleRefresh(Page page, URL url, int arg) throws<BR>&gt;&gt; IOException \
{<BR>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println("handleRefresh");<BR>&gt;&gt; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp;}<BR>&gt;&gt;<BR>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});<BR>&gt;&gt; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// visit Facebook login page and get the Form \
object<BR>&gt;&gt;<BR>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HtmlPage page = \
(HtmlPage)<BR>&gt;&gt; \
webClient.getPage("http://www.facebook.com/login.php");<BR>&gt;&gt; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp;HtmlForm form = \
page.getFormByName("login_form");<BR>&gt;&gt;<BR>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Enter login and passwd<BR>&gt;&gt; &nbsp; &nbsp; \
&nbsp; &nbsp;  &nbsp;form.getInputByName("email").setValueAttribute("<A \
href="mailto:me@email.com" rel=nofollow target=_blank \
ymailto="mailto:me@email.com">me@email.com</A>");<BR>&gt;&gt; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp;form.getInputByName("pass").setValueAttribute("PASS");<BR>&gt;&gt; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Click "Login" \
button/link<BR>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;page = (HtmlPage) \
form.getInputByValue("Login").click();<BR>&gt;&gt;<BR>&gt;&gt; &nbsp; &nbsp; \
}<BR>&gt;&gt; }<BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;&gt; Any idea how I messed this \
up?<BR>&gt;&gt;<BR>&gt;<BR>&gt;<BR></DIV></DIV>&gt; I wasn't able to get that code to \
work, so I switched it to Xpath:<BR>&gt;<BR>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; HtmlForm form =<BR>&gt; page.getFirstByXPath(".//*[@id='login_form']");<BR> \
<DIV class=im>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
form.getInputByName("email").setValueAttribute("<A href="mailto:me@email.com" \
rel=nofollow target=_blank \
ymailto="mailto:me@email.com">me@email.com</A>");<BR></DIV>&gt; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; form.getInputByName("pass").setValueAttribute("pass");<BR> <DIV \
class=im>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; page = (HtmlPage) \
form.getInputByValue("Login").click();<BR>&gt;<BR>&gt;<BR></DIV>&gt; -Thank \
You-<BR>&gt;<BR>&gt;<BR>&gt;<BR><FONT color=#888888><BR>--<BR>View this message in \
context: http://old.nabble.com/facebook-login-tp26780472p26795475.html<BR></FONT> \
<DIV> <DIV></DIV>
<DIV class=h5>Sent from the HtmlUnit - General mailing list archive at <A \
href="http://nabble.com/" \
target=_blank>Nabble.com</A>.<BR><BR><BR>------------------------------------------------------------------------------<BR>Return \
on Information:<BR>Google Enterprise Search pays you back<BR>Get the \
facts.<BR>http://p.sf.net/sfu/google-dev2dev<BR>_______________________________________________<BR>Htmlunit-user \
mailing list<BR><A href="mailto:Htmlunit-user@lists.sourceforge.net" rel=nofollow \
target=_blank ymailto="mailto:Htmlunit-user@lists.sourceforge.net">Htmlunit-user@lists.sourceforge.net</A><BR><A \
href="https://lists.sourceforge.net/lists/listinfo/htmlunit-user" rel=nofollow \
target=_blank>https://lists.sourceforge.net/lists/listinfo/htmlunit-user</A><BR></DIV></DIV></BLOCKQUOTE></DIV><BR><BR \
clear=all><BR>-- <BR>Sander A. Smith<BR>President<BR><BR>Sericon Technology \
Inc.<BR>71 Marquette Ave.<BR>Toronto, Ontario M6A 1X8<BR>(416)781-3988<BR><BR>Link to \
me on LinkedIn<BR>http://www.linkedin.com/in/sandersmith<BR><BR>Join our community of \
people interested in testing Facebook \
applications<BR>http://www.TestFacebook.com<BR><BR>Learn about advanced tools for \
testing social networking \
applications<BR>http://www.FriendRunner.com<BR><BR>http://www.sericontech.com<BR></DIV></DIV><!-- \
cg37.c4.mail.gq1.yahoo.com compressed/chunked Sat Dec 12 08:18:28 PST 2009 \
--></div><br>

      </body></html>



------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 

_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/htmlunit-user


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic