From: Ahmed A. <asa...@ya...> - 2016-07-13 12:14:12
|
Hi Davi, Please read http://htmlunit.sourceforge.net/submittingJSBugs.html Knowing how the website in question works, takes time to investigate. Ahmed From: Davi Medeiros Cabral <dav...@gm...> To: htm...@li... Sent: Sunday, July 10, 2016 1:08 PM Subject: Re: [Htmlunit-user] HtmlUnit, Ajax and Input without submit button Hello, I made some changes in my code, leaving it more complete. Still, it does not work, my code enters an infinite loop in print "Waiting for symbol tag ...". That is, I can not insert a symbol from my code, though I can do it in the browser. BrowserVersion browserVersion = BrowserVersion.FIREFOX_45; WebClient webClient = new WebClient(browserVersion); webClient.setAjaxController(new SyncAjaxController()); webClient.setCookieManager(new CookieManager()); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setCssEnabled(true); webClient.getOptions().setUseInsecureSSL(true); try { System.out.println("Acessing webpage..."); HtmlPage page; page = webClient.getPage( "https://dwq4do82y8xi7.cloudfront.net/bovespa/widgetembed/?symbol=IBOV&interval=1&hidesidetoolbar=0&symboledit=1&toolbarbg=f1f3f6&editablewatchlist=1&details=1&studies=&widgetbarwidth=300&hideideas=1&theme=White&style=3&timezone=exchange&withdateranges=1&studies_overrides=%7B%7D&overrides=%7B%7D&enabled_features=%5B%5D&disabled_features=%5B%5D&locale=pt&utmsource=www.bmfbovespa.com.br&utmmedium=www.bmfbovespa.com.br/pt_br/servicos/market-data/cotacoes/"); List<Node> nodesAdicionarSimbolo = null; while (nodesAdicionarSimbolo == null || (nodesAdicionarSimbolo != null && nodesAdicionarSimbolo.size() == 0)) { nodesAdicionarSimbolo = (List<Node>) page.getByXPath("//input[@placeholder='Adicionar Símbolo']"); System.out.println("Looking for 'Adicionar Símbolo'..."); } System.out.println("'Adicionar Símbolo' found!"); { String symbol = "BBAS3"; HtmlTextInput inputAdicionarSimbolo = (HtmlTextInput) nodesAdicionarSimbolo.get(0); System.out.println("Putting symbol in 'Adicionar Símbolo'..."); inputAdicionarSimbolo.setTextContent(symbol); { HtmlElement input = (HtmlElement) inputAdicionarSimbolo; input.focus(); input.type(symbol); System.out.println("Pressing the Enter key..."); page = (HtmlPage) input.type('\n'); } } { List<Node> nodesCotacaoDiaria; do { nodesCotacaoDiaria = (List<Node>) page.getByXPath("//div[@class='symbol']"); System.out.println("Waiting for symbol tag..."); } while (nodesCotacaoDiaria == null || (nodesCotacaoDiaria != null && nodesCotacaoDiaria.size() == 0)); System.out.println("Symbol tag found!"); } } catch (Exception e) { e.printStackTrace(); } webClient.close(); |