Quantcast

HtmlSelect doesnt trigger the events

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

HtmlSelect doesnt trigger the events

jplistero
Hi there, 

I am building a spider for a web site that has two combo boxes, the first one populates the second one. 

this it is done with a java script:

  $('#gender').change(function () {

            if ($('#gender').val() == 'Female') {

                marital_options = '';
                var selected = '';
                $.each(marital_status_female, function (index, value) {
                    if (value == 1) {
                        selected = 'selected="selected"';
                    } else {
                        selected = '';
                    }
                    marital_options += '<option ' + selected + ' value="' + index + '">' + value + '</option>';
                });
                $('#marital_status').html('<select class="form-control" id="marital_status" name="marital_status">' + marital_options + '</select>');

this is my code 

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

webClient.setJavaScriptTimeout(5000);
webClient.getOptions().setThrowExceptionOnScriptError(true);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.waitForBackgroundJavaScript(30000);
webClient.getOptions().setUseInsecureSSL(true);

...

final HtmlSelect gender = page.getFirstByXPath("//*[@id=\"gender\"]");
gender.setSelectedAttribute(gender.getOptionByValue("Male"),Boolean.TRUE);

final HtmlSelect marital_status = page.getFirstByXPath("//*[@id=\"marital_status\"]");
marital_status.getOptions(); // this is EMPTY 


Any clue how to make it works ? 

thank you in advance ! 
JP_Listero




------------------------------------------------------------------------------
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
|  
Report Content as Inappropriate

Re: HtmlSelect doesnt trigger the events

asashour
Hi,

You need to provide complete (hopefully tiny) case, so others can reproduce your issue.


Ahmed



From: jp_listero <[hidden email]>
To: [hidden email]
Sent: Tuesday, April 18, 2017 11:56 PM
Subject: [Htmlunit-user] HtmlSelect doesnt trigger the events

Hi there, 

I am building a spider for a web site that has two combo boxes, the first one populates the second one. 

this it is done with a java script:

  $('#gender').change(function () {

            if ($('#gender').val() == 'Female') {

                marital_options = '';
                var selected = '';
                $.each(marital_status_female, function (index, value) {
                    if (value == 1) {
                        selected = 'selected="selected"';
                    } else {
                        selected = '';
                    }
                    marital_options += '<option ' + selected + ' value="' + index + '">' + value + '</option>';
                });
                $('#marital_status').html('<select class="form-control" id="marital_status" name="marital_status">' + marital_options + '</select>');

this is my code 

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

webClient.setJavaScriptTimeout(5000);
webClient.getOptions().setThrowExceptionOnScriptError(true);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.waitForBackgroundJavaScript(30000);
webClient.getOptions().setUseInsecureSSL(true);

...

final HtmlSelect gender = page.getFirstByXPath("//*[@id=\"gender\"]");
gender.setSelectedAttribute(gender.getOptionByValue("Male"),Boolean.TRUE);

final HtmlSelect marital_status = page.getFirstByXPath("//*[@id=\"marital_status\"]");
marital_status.getOptions(); // this is EMPTY 


Any clue how to make it works ? 

thank you in advance ! 
JP_Listero


------------------------------------------------------------------------------
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
Loading...