click doesn't work

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

click doesn't work

jplistero
Hi there, 

I am spidering a web page ... but click() doesnt work, or doesn't navigate ...

Any clue what could be the issue ? I'm using 2.25 version 

this my code:

@Test
public String getFacturas() throws Exception {

try (final WebClient webClient = new WebClient(BrowserVersion.getDefault())) {

webClient.setJavaScriptTimeout(15000);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setJavaScriptEnabled(false);
webClient.waitForBackgroundJavaScript(30000);
webClient.getOptions().setActiveXNative(true);
webClient.getOptions().setAppletEnabled(true);
webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setRedirectEnabled(true);

// add to log variable
//toLog.append(" contrato: ").append(numeroContrato);

final HtmlPage consultaCuentaPage = webClient.getPage("https://wse-prod.antel.com.uy/ConsultaCFE/form/consultarCuenta.jsf");

// grab first form
final HtmlForm consultarCuentaForm = consultaCuentaPage.getForms().get(0);

// numero cuenta input
final HtmlInput numeroCuentaInput = consultarCuentaForm.getInputByName("nroCuenta");

// consultar button
final HtmlInput consultarButton = consultarCuentaForm.getInputByName("commandConsultar");

// Change the value of the text field
numeroCuentaInput.setValueAttribute("16000455000231");

// Now submit the form by clicking the button and get back the second page.
final HtmlPage consultaCuentaPage2 = consultarButton.click();
LOG.info("time: " + consultaCuentaPage2.getWebResponse().getLoadTime());
// LOG.info("time: " + consultaCuentaPage2.getWebResponse().getContentAsString());

//System.out.println(consultaCuentaPage2.asText());

////*[@id="form"]/div[1]/fieldset/table/tbody/tr[1]/td[1] 
if (consultaCuentaPage2.getFirstByXPath("//*[@id=\"form\"]/div[1]/fieldset/table/tbody/tr[1]/td[1]") != null) {
return ((HtmlTableDataCell)consultaCuentaPage2.getFirstByXPath("//*[@id=\"form\"]/div[1]/fieldset/table/tbody/tr[1]/td[1]")).asText();
}
}
return null;
}

best regards ! 




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Htmlunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
Reply | Threaded
Open this post in threaded view
|

Re: click doesn't work

asashour
Hi,

You need to isolate a minimal case, please read http://htmlunit.sourceforge.net/submittingJSBugs.html

Ahmed


From: jp_listero <[hidden email]>
To: [hidden email]
Sent: Thursday, March 30, 2017 8:18 PM
Subject: [Htmlunit-user] click doesn't work

Hi there, 

I am spidering a web page ... but click() doesnt work, or doesn't navigate ...

Any clue what could be the issue ? I'm using 2.25 version 

this my code:

@Test
public String getFacturas() throws Exception {

try (final WebClient webClient = new WebClient(BrowserVersion. getDefault())) {

webClient. setJavaScriptTimeout(15000);
webClient.getOptions(). setThrowExceptionOnScriptError (false);
webClient.getOptions(). setJavaScriptEnabled(false);
webClient. waitForBackgroundJavaScript( 30000);
webClient.getOptions(). setActiveXNative(true);
webClient.getOptions(). setAppletEnabled(true);
webClient.getOptions(). setCssEnabled(true);
webClient.getOptions(). setUseInsecureSSL(true);
webClient.getOptions(). setRedirectEnabled(true);

// add to log variable
//toLog.append(" contrato: ").append(numeroContrato);

final HtmlPage consultaCuentaPage = webClient.getPage("https:// wse-prod.antel.com.uy/ ConsultaCFE/form/ consultarCuenta.jsf");

// grab first form
final HtmlForm consultarCuentaForm = consultaCuentaPage.getForms(). get(0);

// numero cuenta input
final HtmlInput numeroCuentaInput = consultarCuentaForm. getInputByName("nroCuenta");

// consultar button
final HtmlInput consultarButton = consultarCuentaForm. getInputByName(" commandConsultar");

// Change the value of the text field
numeroCuentaInput. setValueAttribute(" 16000455000231");

// Now submit the form by clicking the button and get back the second page.
final HtmlPage consultaCuentaPage2 = consultarButton.click();
LOG.info("time: " + consultaCuentaPage2. getWebResponse().getLoadTime() );
// LOG.info("time: " + consultaCuentaPage2. getWebResponse(). getContentAsString());

//System.out.println( consultaCuentaPage2.asText());

////*[@id="form"]/div[1]/ fieldset/table/tbody/tr[1]/td[ 1] 
if (consultaCuentaPage2. getFirstByXPath("//*[@id=\" form\"]/div[1]/fieldset/table/ tbody/tr[1]/td[1]") != null) {
return ((HtmlTableDataCell) consultaCuentaPage2. getFirstByXPath("//*[@id=\" form\"]/div[1]/fieldset/table/ tbody/tr[1]/td[1]")).asText();
}
}
return null;
}

best regards ! 



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Htmlunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-user



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Htmlunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
Reply | Threaded
Open this post in threaded view
|

Re: click doesn't work

jplistero
Hi

I am not sure how to do it for this case,

this is de code  for the button:

<input class="botonSub" id="commandConsultar" name="commandConsultar" onclick="A4J.AJAX.Submit('_viewRoot','form',event,{'similarityGroupingId':'commandConsultar','parameters':{'commandConsultar':'commandConsultar'} ,'actionUrl':'/ConsultaCFE/form/consultarCuenta.jsf;jsessionid=EDB70DE7649D858CA52C25C1855C8F9D'} );return false;" value="Consultar >>" type="button">

Kind of lost here, I am not sure what else try it.

thank you in advance.
Reply | Threaded
Open this post in threaded view
|

Re: click doesn't work

asashour
Hi,



To find the offending line, you can put alert() at various places, compare the result of HtmlUnit to a real browser (Chrome, Firefox or Internet Explorer), and you will mostly be able to provide a tiny failing test case which contains few lines of JavaScript (independent of the whole JavaScript library), please have a look at some sample test cases.
Once the cause is identified, it is very likely to be fixed in a timely manner.




From: jplistero <[hidden email]>
To: [hidden email]
Sent: Friday, March 31, 2017 4:06 PM
Subject: Re: [Htmlunit-user] click doesn't work

Hi

I am not sure how to do it for this case,

this is de code  for the button:

<input class="botonSub" id="commandConsultar" name="commandConsultar"
onclick="A4J.AJAX.Submit('_viewRoot','form',event,{'similarityGroupingId':'commandConsultar','parameters':{'commandConsultar':'commandConsultar'}
,'actionUrl':'/ConsultaCFE/form/consultarCuenta.jsf;jsessionid=EDB70DE7649D858CA52C25C1855C8F9D'}
);return false;" value="Consultar >>" type="button">

Kind of lost here, I am not sure what else try it.

thank you in advance.



--
View this message in context: http://htmlunit.10904.n7.nabble.com/click-doesn-t-work-tp41322p41328.html
Sent from the HtmlUnit - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Htmlunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-user



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Htmlunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
Reply | Threaded
Open this post in threaded view
|

Re: click doesn't work

jplistero
Hi asashour,

thank you for the support, I read it, I understand that I need to isolate the problem, add alert anotations, etc.

I'm very new to this and I don't get how to isolate the java script and where is the Java script ... I am only see the A4J.AJAX.Submit ...

Can you help me with this ?

best
Reply | Threaded
Open this post in threaded view
|

Re: click doesn't work

jplistero
Hi there,

nevermind, issue solved with this setup:

webClient.setAjaxController(new NicelyResynchronizingAjaxController());

full setup

try (final WebClient webClient = new WebClient(BrowserVersion.getDefault())) {

                                webClient.setJavaScriptTimeout(15000);
                                webClient.getOptions().setJavaScriptEnabled(true);
                                webClient.getOptions().setThrowExceptionOnScriptError(false);
                                webClient.getOptions().setCssEnabled(false);
                                webClient.setAjaxController(new NicelyResynchronizingAjaxController());
                                webClient.getOptions().setThrowExceptionOnScriptError(false);

....

best