[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> </DIV>
<DIV>Public sites like facebook changes frequently.</DIV>
<DIV> </DIV>
<DIV>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.</DIV> <DIV> </DIV>
<DIV>Regarding the below case, the API was incorrectly used:</DIV>
<DIV> </DIV>
<DIV>In the source of facebook login:</DIV>
<DIV> </DIV>
<DIV> \
<form method="POST" action="..." <FONT color=#ff0000>id</FONT>="login_form" \
onsubmit="..."></DIV> <DIV> </DIV>
<DIV>This can be accessed by:</DIV>
<DIV> </DIV>
<DIV> page.getElementById("login_form")</DIV>
<DIV> </DIV>
<DIV>Not by:</DIV>
<DIV> </DIV>
<DIV> page.getFormByName("login_form");</DIV>
<DIV> </DIV>
<DIV>Because the form does not have a name.</DIV>
<DIV> </DIV>
<DIV> </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 \
<smithsa@sericontech.com><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> </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 built by \
volunteers, so I'll give you guys some slack and appreciate all of the stuff that \
DOES work.</DIV> <DIV> </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> </DIV>
<DIV>Sander<BR><BR></DIV>
<DIV class=gmail_quote>On Tue, Dec 15, 2009 at 9:15 AM, Ahmed Ashour <SPAN \
dir=ltr><<A href="mailto:asashour@yahoo.com" rel=nofollow target=_blank \
ymailto="mailto:asashour@yahoo.com">asashour@yahoo.com</A>></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>><BR>><BR>><BR>> \
ihavealegohead wrote:<BR>>><BR>>> I am testing htmlunit with facebook. \
I try a login, but fails:<BR>>><BR>>> run:<BR>>> Dec 14, 2009 \
5:50:12 PM<BR>>> com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl \
notify<BR>>> WARNING: Expected content type of 'application/javascript' \
or<BR>>> 'application/ecmascript' for remotely loaded JavaScript element \
at<BR>>> 'http://b.static.ak.fbcdn.net/rsrc.php/zCOXE/hash/dbni8t78.js', but \
got<BR>>> 'application/x-javascript'.<BR>>> Exception in thread \
"main"<BR>>> com.gargoylesoftware.htmlunit.ElementNotFoundException:<BR>>> \
elementName=[form] attributeName=[name] attributeValue=[login_form]<BR>>> \
at<BR>>> \
com.gargoylesoftware.htmlunit.html.HtmlPage.getFormByName(HtmlPage.java:588)<BR>>> \
at fblogin.Main.main(Main.java:36)<BR>>> Java \
Result: 1<BR>>> BUILD SUCCESSFUL (total time: 10 \
seconds)<BR>>><BR>>><BR>>> Indeed, the login form attribute is \
login_form:<BR>>><BR>>> <form method="POST"<BR>>> 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>>> \
id="login_form"><BR>>><BR>>> Here is my \
source:<BR>>><BR>>> package fblogin;<BR>>> import <A \
href="http://java.io.io/" target=_blank>java.io</A>.IOException;<BR>>> import \
<A href="http://java.net/" target=_blank>java.net</A>.URL;<BR>>><BR>>> \
import com.gargoylesoftware.htmlunit.BrowserVersion;<BR>>> import \
com.gargoylesoftware.htmlunit.Page;<BR>>> import \
com.gargoylesoftware.htmlunit.RefreshHandler;<BR>>> import \
com.gargoylesoftware.htmlunit.WebClient;<BR>>> import \
com.gargoylesoftware.htmlunit.html.HtmlForm;<BR>>> import \
com.gargoylesoftware.htmlunit.html.HtmlPage;<BR>>><BR>>><BR>>><BR>>> \
/**<BR>>> *<BR>>> * @author me<BR>>> \
*/<BR>>> public class Main {<BR>>><BR>>> \
/**<BR>>> * @param args the command line \
arguments<BR>>> */<BR>>> public static \
void main(String[] args) throws Exception {<BR>>> \
// Create and initialize WebClient object<BR>>> \
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);<BR>>> \
\
webClient.setThrowExceptionOnScriptError(false);<BR>>> \
webClient.setRefreshHandler(new RefreshHandler() {<BR>>> \
public \
void handleRefresh(Page page, URL url, int arg) throws<BR>>> IOException \
{<BR>>> \
System.out.println("handleRefresh");<BR>>> \
\
}<BR>>><BR>>> });<BR>>> \
// visit Facebook login page and get the Form \
object<BR>>><BR>>> HtmlPage page = \
(HtmlPage)<BR>>> \
webClient.getPage("http://www.facebook.com/login.php");<BR>>> \
HtmlForm form = \
page.getFormByName("login_form");<BR>>><BR>>> \
// Enter login and passwd<BR>>> \
form.getInputByName("email").setValueAttribute("<A \
href="mailto:me@email.com" rel=nofollow target=_blank \
ymailto="mailto:me@email.com">me@email.com</A>");<BR>>> \
form.getInputByName("pass").setValueAttribute("PASS");<BR>>> \
// Click "Login" \
button/link<BR>>> page = (HtmlPage) \
form.getInputByValue("Login").click();<BR>>><BR>>> \
}<BR>>> }<BR>>><BR>>><BR>>> Any idea how I messed this \
up?<BR>>><BR>><BR>><BR></DIV></DIV>> I wasn't able to get that code to \
work, so I switched it to Xpath:<BR>><BR>> \
HtmlForm form =<BR>> page.getFirstByXPath(".//*[@id='login_form']");<BR> \
<DIV class=im>> \
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>> \
form.getInputByName("pass").setValueAttribute("pass");<BR> <DIV \
class=im>> page = (HtmlPage) \
form.getInputByValue("Login").click();<BR>><BR>><BR></DIV>> -Thank \
You-<BR>><BR>><BR>><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