From: Ahmed A. <asa...@ya...> - 2015-05-23 07:42:56
|
Hi Roberto, The build failed, and so it wasn't updated. Now it is green, and the artifacts are built. Please try again. Ahmed From: Roberto Bottoni - AfterBit <r.b...@af...> To: Ahmed Ashour <asa...@ya...>; htm...@li... Sent: Friday, May 22, 2015 12:48 PM Subject: Re: [Htmlunit-user] Browser back button Hi Ahmed.. i changed my code, overwriting your code.. but..now this System.out.println("Text Source AFTER : \n" + ((HtmlPage) browser.getWebWindows().get(0).getEnclosedPage()).asText() + "\n"); displays a black page.. Thanks Roberto. ----- Original Message ----- From: Ahmed Ashour To: htm...@li... Sent: Friday, May 22, 2015 10:40 AM Subject: Re: [Htmlunit-user] Browser back button Hi Roberto, This was just fixed. Please get SVN or latest snapshot from the build server once the queued build is green (https://ci.canoo.com/teamcity/viewType.html?buildTypeId=HtmlUnit_QuickBuild) Also, please note you need to update the page, namely: System.out.println("Text Source BEFORE : \n" + ((HtmlPage) browser.getWebWindows().get(0).getEnclosedPage()).asText() + "\n"); page.getEnclosingWindow().getHistory().back(); System.out.println("history.getIndex() : " + history.getIndex()); System.out.println("Text Source AFTER : \n" + ((HtmlPage) browser.getWebWindows().get(0).getEnclosedPage()).asText() + "\n"); Thanks, Ahmed From: Ahmed Ashour <asa...@ya...> To: "htm...@li..." <htm...@li...> Sent: Thursday, May 21, 2015 2:25 PM Subject: Re: [Htmlunit-user] Browser back button Hi Roberto, This is because history currently handles only GET requests, not POST. Please open a bug ticket. Ahmed From: Roberto Bottoni - AfterBit <r.b...@af...> To: Ahmed Ashour <asa...@ya...>; htm...@li... Sent: Thursday, May 21, 2015 11:02 AM Subject: Re: [Htmlunit-user] Browser back button Hi, this is my code .. the code (doUASC() ) try to get some data from a page : browser.getPage("http://uasconline.uasc.net/Home"); and then do a "back page" : System.out.println(" trying to go back ..."); History history = browser.getWebWindows().get(0).getHistory(); // trying to go BACK !!! System.out.println("history.getIndex() : " + history.getIndex()); System.out.println("Text Source BEFORE : \n" + page.asText() + "\n"); page.getEnclosingWindow().getHistory().back(); System.out.println("history.getIndex() : " + history.getIndex()); System.out.println("Text Source AFTER : \n" + page.asText() + "\n"); follows the full code . Thanks! Roberto package uasc; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.*; import com.gargoylesoftware.htmlunit.WebAssert.*; import com.gargoylesoftware.htmlunit.RefreshHandler; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebWindow; import com.gargoylesoftware.htmlunit.CookieManager; import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController; import com.gargoylesoftware.htmlunit.History; import com.gargoylesoftware.htmlunit.ScriptResult; import com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDivElement; import com.gargoylesoftware.htmlunit.javascript.host.Event; import com.gargoylesoftware.htmlunit.javascript.background.*; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.HttpMethod; import org.apache.commons.lang3.StringUtils; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.io.IOException; import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.*; import java.text.*; import java.net.URL; import java.util.LinkedList; import java.util.List; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebWindow; import com.gargoylesoftware.htmlunit.WebWindowEvent; import com.gargoylesoftware.htmlunit.WebWindowListener; import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; public class UASC { static final WebClient browser; static final LinkedList<WebWindow> windows = new LinkedList<WebWindow>(); static { browser = new WebClient(BrowserVersion.FIREFOX_24); browser.getOptions().setJavaScriptEnabled(true); browser.setAjaxController(new NicelyResynchronizingAjaxController()); CookieManager cookieMan = new CookieManager(); cookieMan = browser.getCookieManager(); cookieMan.setCookiesEnabled(true); browser.getOptions().setRedirectEnabled(true); browser.getOptions().setThrowExceptionOnFailingStatusCode(false); browser.getOptions().setPrintContentOnFailingStatusCode(true); browser.getOptions().setThrowExceptionOnScriptError(false); //browser.getOptions().isPopupBlockerEnabled(); browser.addWebWindowListener(new WebWindowListener() { public void webWindowClosed(WebWindowEvent event) { System.out.println("---------------------------------------------- a window is CLOSED: " + event.getOldPage()); } public void webWindowContentChanged(WebWindowEvent event) { System.out.println("---------------------------------------------- webWindowContentChanged: "); } public void webWindowOpened(WebWindowEvent event) { System.out.println("---------------------------------------------- a NEW window opened: " + event.getNewPage()); windows.add(event.getWebWindow()); } }); } public static void main(String[] args) { doUASC(); } private static void doUASC() { try { // ------------------------------------------------------------------ search form HtmlPage page = (HtmlPage) browser.getPage("http://uasconline.uasc.net/Home"); String xpath = "//input[contains(@id, 'trackText')]"; HtmlTextInput searchTerm = (HtmlTextInput) page.getByXPath(xpath).get(0); xpath = "//a[contains(@onclick, 'subOnlineTrack()')]"; HtmlAnchor anchor = (HtmlAnchor) page.getByXPath(xpath).get(0); searchTerm.setText("CNQIN141696"); // booking number page = (HtmlPage) anchor.click(); List<HtmlElement> aEs = new ArrayList<HtmlElement>(); xpath = "//table[contains(@id, 'table-trackSummary')]"; HtmlTable table = (HtmlTable) page.getByXPath(xpath).get(0); for (HtmlTableRow row : table.getRows()) { String a_xpath = "a"; // anchor link HtmlElement cont_anchor = row.getCells().size() != 9 ? null : (HtmlElement) row.getCell(2).getFirstByXPath(a_xpath); if (cont_anchor != null && cont_anchor instanceof HtmlAnchor) { String cont_number = StringUtils.remove(row.getCell(2).asText(), " "); if (checkContainerNumber(cont_number)) { aEs.add(cont_anchor); break; } } } Iterator aeit = aEs.iterator(); while (aeit.hasNext()) { HtmlElement aE = (HtmlElement) aeit.next(); try { xpath = "//table[contains(@id, 'table-trackSummary')]"; table = (HtmlTable) page.getByXPath(xpath).get(0); for (HtmlTableRow row : table.getRows()) { String a_xpath = "a"; // anchor link HtmlElement cont_anchor = row.getCells().size() != 9 ? null : (HtmlElement) row.getCell(2).getFirstByXPath(a_xpath); if (cont_anchor != null && cont_anchor instanceof HtmlAnchor && StringUtils.containsIgnoreCase(aE.getTextContent(), cont_anchor.getTextContent())) { page = cont_anchor.click(); xpath = "//table[contains(@id, 'table-trackContainer')]"; List<HtmlTable> det_tables = (List<HtmlTable>) page.getByXPath(xpath); // do something... System.out.println(" trying to go back ..."); History history = browser.getWebWindows().get(0).getHistory(); // trying to go BACK !!! System.out.println("history.getIndex() : " + history.getIndex()); System.out.println("Text Source BEFORE : \n" + page.asText() + "\n"); page.getEnclosingWindow().getHistory().back(); System.out.println("history.getIndex() : " + history.getIndex()); System.out.println("Text Source AFTER : \n" + page.asText() + "\n"); break; } } } catch (Exception e) { System.out.println(e.toString()); } } if (true) { browser.closeAllWindows(); return; } } catch (Exception e) { System.out.println(e.toString()); } } private static boolean checkContainerNumber(String txt) { boolean match = false; if (!StringUtils.isEmpty(StringUtils.trim(txt))) { //String txt="abcd1234567"; String re1 = "((?:[a-z][a-z]+))"; // Word 1 String re2 = "(\\d+)"; // Integer Number 1 Pattern p = Pattern.compile(re1 + re2, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(txt); match = m.find(); } return match; } } ----- Original Message ----- From: Ahmed Ashour To: htm...@li... Sent: Thursday, May 21, 2015 9:49 AM Subject: Re: [Htmlunit-user] Browser back button Hi, Then please post your complete case. Ahmed From: Roberto Bottoni - AfterBit <r.b...@af...> To: Ahmed Ashour <asa...@ya...>; htm...@li... Sent: Thursday, May 21, 2015 9:45 AM Subject: Re: [Htmlunit-user] Browser back button Hi, it doesn't work.. i've tried this : page.asText(); page.getEnclosingWindow().getHistory().back(); page.asText(); but I see the same page Roberto ----- Original Message ----- From: Ahmed Ashour To: htm...@li... Sent: Thursday, May 21, 2015 1:48 AM Subject: Re: [Htmlunit-user] Browser back button Hi, You can get WebClient/Page from each other by something like: webClient.getWebWindows().get(0).getEnclosedPage(); page.getEnclosingWindow().getHistory().back(); Ahmed From: Roberto Bottoni - AfterBit <r.b...@af...> To: htm...@li... Sent: Wednesday, May 20, 2015 7:13 PM Subject: [Htmlunit-user] Browser back button Hi, I would like to simulate the browser "back button" and get the Html Page i searched internet.. and i have found this : webClient.getWebWindows().get(0).getHistory().back(); but.. how can i get the Html Page (if works the above command ) ? Thanks! Roberto ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user |