From: Mark F. <sen...@gm...> - 2015-09-06 19:15:35
|
Hi htmlunit users, Has anyone successfully used htmlunit with Quickbooks Online's (QBO) OAuth process? Somewhat different from other OAuth examples and can't seem to navigate through the various pages. I successfully provide credentials and submit the first form but immediately face trouble. Depending upon the number of QBO company files, the next form requires company selection or, if only one exists, form redirects to final form with "Authorize" button. I only have one company file at the moment so expecting to find the Authorize button... final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38); webClient.setAjaxController(new NicelyResynchronizingAjaxController()); final HtmlPage page1 = webClient.getPage(url); HtmlForm form = null; for (int i = 0; i < 20; i++) { if ((form = page1.getFirstByXPath("//*[@id='ius-sign-in']/form")) != null) { break; } synchronized (page1) { page1.wait(500); } } final HtmlSubmitInput button = form.getInputByName("SignIn"); final HtmlTextInput textField = form.getInputByName("Email"); final HtmlPasswordInput textField2 = form.getInputByName("Password"); // Change the value of the text field textField.setValueAttribute(QBO_USERNAME); textField2.setValueAttribute(QBO_PASSWORD); final HtmlPage page2 = button.click(); /*/Above appears to work..here's where I expect the Authorize button on a form...* for (int i = 0; i < 20; i++) { if ((form = page2.getFirstByXPath("//*[@id='grantForm']")) != null) { break; } synchronized (page2) { page2.wait(500); } } 'form' value is always null regardless of the loop length above. I've tried xpath searching for the button id as well but still no joy. Plenty of htmlunit warnings but process continues even after the following... ... INFO: sign in success Sep 06, 2015 2:04:50 PM com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl runSingleJob SEVERE: Job run failed with unexpected RuntimeException: TypeError: Cannot read property "ius" from undefined (script in https://accounts.intuit.com/xdr.html?v2=true from (149, 33) to (162, 11)#156) ======= EXCEPTION START ======== EcmaError: lineNumber=[156] column=[0] lineSource=[<no source>] name=[TypeError] sourceName=[script in https://accounts.intuit.com/xdr.html?v2=true from (149, 33) to (162, 11)] message=[TypeError: Cannot read property "ius" from undefined (script in https://accounts.intuit.com/xdr.html?v2=true from (149, 33) to (162, 11)#156)] com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "ius" from undefined (script in https://accounts.intuit.com/xdr.html?v2=true from (149, 33) to (162, 11)#156) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.handleJavaScriptException(JavaScriptEngine.java:953) ... Would love to here any experiences or thoughts from those with ideas or interested in final solution. Happy to answer any questions or provide more detail. Best regards |