From: Stephen M. <ste...@gm...> - 2017-10-16 00:12:31
|
At the end of the day I need to programmatically visit this url: https://<sharepointroot>.sharepoint.com/sites/<o365 group name>/_layouts/15/groupstatus.aspx?Target=NOTEBOOK I have tried this: com.gargoylesoftware.htmlunit.WebClient webClient = new com.gargoylesoftware.htmlunit.WebClient( com.gargoylesoftware.htmlunit.BrowserVersion.FIREFOX_45 ); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setCssEnabled(false); // I think this speeds the thing up webClient.getOptions().setRedirectEnabled(true); webClient.setAjaxController(new com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController()); webClient.getCookieManager().setCookiesEnabled(true); webClient.setAlertHandler(new com.gargoylesoftware.htmlunit.AlertHandler() { public void handleAlert( com.gargoylesoftware.htmlunit.Page page, String message) { log.warn( message ); } }); webClient.addWebWindowListener( new com.gargoylesoftware.htmlunit.WebWindowListener() { @Override public void webWindowClosed( com.gargoylesoftware.htmlunit.WebWindowEvent event ) { log.info( "Closed" ); } @Override public void webWindowContentChanged( com.gargoylesoftware.htmlunit.WebWindowEvent event) { log.info( "2nd Page : " + event ); } @Override public void webWindowOpened( com.gargoylesoftware.htmlunit.WebWindowEvent event) { log.info( "Opened" ); } }); com.gargoylesoftware.htmlunit.html.HtmlPage page = webClient.getPage( "https://<sharepointroot>.sharepoint.com/sites/<o365 group name>/_layouts/15/groupstatus.aspx?Target=NOTEBOOK" ); com.gargoylesoftware.htmlunit.html.HtmlForm form = page.getHtmlElementById( "credentials" ); log.info( "creds: " + form ); com.gargoylesoftware.htmlunit.html.HtmlEmailInput userid = page.getHtmlElementById( "cred_userid_inputtext" ); userid.setValueAttribute("<userid>"); com.gargoylesoftware.htmlunit.html.HtmlPasswordInput password = page.getHtmlElementById( "cred_password_inputtext" ); password.setValueAttribute("<password>"); com.gargoylesoftware.htmlunit.html.HtmlButton button = page.getHtmlElementById( "cred_sign_in_button"); log.info( "obj: " + button ); log.info( "PRE - HIT BUTTON" ); button.click(); log.info( "POST - HIT BUTTON" ); But it looks like I am just getting back the main login screen. The logging output looks like: 2017-10-15 20:00:45,142 WARN [IncorrectnessListenerImpl:38] () Obsolete content type encountered: 'application/x-javascript'. 2017-10-15 20:00:45,303 ERROR [StrictErrorReporter:82] () runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector: :x).] sourceName=[ https://secure.aadcdn.microsoftonline-p.com/ests/2.1.6693.13/content/cdnbundles/jquery.1.11.min.js] line=[2] lineSource=[null] lineOffset=[0] 2017-10-15 20:00:45,384 WARN [IncorrectnessListenerImpl:38] () Obsolete content type encountered: 'application/x-javascript'. 2017-10-15 20:00:45,513 INFO [AppTest:46] () 2nd Page : WebWindowEvent(source=[TopLevelWindow[name=""]] type=[CHANGE] oldPage=[null] newPage=[HtmlPage( https://login.microsoftonline.com/45759b01-d1ea-48ff-b30d-1c64ce38b9dc/oauth2/authorize?client_id=00000003-0000-0ff1-ce00-000000000000&response_mode=form_post&response_type=code%20id_token&resource=00000003-0000-0ff1-ce00-000000000000&scope=openid&nonce=4992A006C932B1234F853A2DB5D6FC406E000B216379F8A5-0AFFAB897525A7130B8C49C9E0D2DCEE954C6A61121FF4CDD6E164B67A10655A&redirect_uri=https:%2F%2F <sharepointroot>.sharepoint.com %2F_forms%2Fdefault.aspx&state=0&wsucxt=1&client-request-id=864a239e-3090-4000-8841-fe092e5084bc)@1391119179]) 2017-10-15 20:00:45,795 INFO [AppTest:59] () creds: HtmlForm[<form id="credentials" method="post" action="/45759b01-d1ea-48ff-b30d-1c64ce38b9dc/login">] 2017-10-15 20:00:45,795 INFO [AppTest:68] () obj: HtmlButton[<button id="cred_sign_in_button" class="button normaltext cred_sign_in_button refresh_domain_state control-button button-two button_primary" style="opacity: 1.0;">] 2017-10-15 20:00:45,795 INFO [AppTest:70] () PRE - HIT BUTTON 2017-10-15 20:00:45,827 INFO [NicelyResynchronizingAjaxController:63] () Re-synchronized call to https://login.microsoftonline.com/common/userrealm?user= <userid>%40<sharepointroot>.onmicrosoft.com &api-version=2.1&stsRequest=rQIIAaWRO4vUUACFcyezYUcEF7HYUnQr4Sb3ndyA4M1LdMFZLSwEWTJ5MIHJJJvc2VHBTsRysLSwsByw0ErEX7BYbO0vECuxshJ3sLEU_IrDKQ_fuWZiG_t76A8UbhKissQwKzbtL7qL53ZeX739fIWMGy_Ur5F98OzTGvhTrdved5y-Tju9TLVO6zYvju1-mnZF21RzbWdN7RyWTVf3Tl6U6WKm7bRvH30A4BSArwCsB0dMSqIQEqGkJMCEssTjVJEo4JFIQoZEfLYgIFhQVyae4hCpJFGBJ11OuHIxRYEXMhnKGEUkCuNYchYKJTAmOElYGEUixoIFwlUYCc7Vl8GFsVroKdlE01VPih-D0WbjYdv0-pUJ0Nr8Jy3vzT3GXS4nCMMcFylkXlnCCUU5xJlgWUG9icyzE9Nq2mJe5adD8G14Hpn-9ra1A3aNy8bPIXizdSb3yjtRPni6HL_sPl-Cbx8aJ1tOcMAxn81xs0iWj-_ktBLIvX9cy_m9_eV-NZveHN-qPdIdOd3d68THKwusLOu7ZXwc_ccvvwE1&checkForMicrosoftAccount=true 2017-10-15 20:00:45,944 INFO [AppTest:74] () POST - HIT BUTTON Has anyone been able to login to office 365 using HtmlUnit ? |