2016-10-23 3 views
0

私はHtmlUnitライブラリ使用してFacebookにログインしようとしていますから、ボタンを取得:次のエラーが発生し、このコードを実行した後HtmlUnit - フォーム

<input value="Zaloguj się" tabindex="4" type="submit" id="u_0_0"> 

:私はボタンの値をチェックして

String loginURL = "https://www.facebook.com/login.php?login_attempt=1" 

final WebClient webClient = new WebClient(); 
HtmlPage page1 = webClient.getPage(loginURL); 
final HtmlForm form = page1.getForms().get(0); 
webClient.setJavaScriptTimeout(45000); 

final HtmlTextInput textField = form.getInputByName("email"); 
textField.setValueAttribute(login); 
final HtmlPasswordInput textField2 = form.getInputByName("pass"); 
textField2.setValueAttribute(password); 
page1 = (HtmlPage) form.getInputByValue("Zaloguj się").click(); 

を:

Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[input] attributeName=[value] attributeValue=[Zaloguj się] 

ここにバグはありますか?助けを おかげで:)

答えて

1

私は「https://www.facebook.com/login.php?login_attempt=1」に述べたURLを閲覧しようとすると、[Zaloguj SIE]値と[いいえ]ボタンがありません。おそらくあなたのコンピュータは英語以外のデフォルト言語を使用している可能性があります。

IDでログインボタンを取得してから、()をクリックすることをお勧めします。

page1.getElementById( "loginbutton")。click();

これは、ログインボタンがIDを持っているのがわかるからです。

<button value="1" class="_42ft _4jy0 _52e0 _4jy6 _4jy1 selected _51sy" id="loginbutton" name="login" tabindex="1" type="submit">Log In</button> 
+0

ありがとうございました!それは働いている!