I am trying to log into a website and retrieve a page of a specific product. My Java code is as follows:
String log = page.executeJavaScript(
"document.getElementById(\"form_postalcode\").innerHTML = \"<select id='cl_postal_code' class='postalCodesSelect form-control form_field select2-hidden-accessible' data-validation-engine='validate[required]' title='' data-toggle='tooltip' data-placeholder='Código Postal' tabindex='-1' data-original-title='Por favor, selecciona un código postal' aria-hidden='true'><option></option><option value='05289'>05289</option><option value='05520'>05520</option><option value='15001'>15001</option><option value='15002'>15002</option></select><span class='select2 select2-container select2-container--default select2-container--above select2-container--open' dir='ltr' style='width: 210px;'><span class='selection'><span class='select2-selection select2-selection--single' role='combobox' aria-autocomplete='list' aria-haspopup='true' aria-expanded='true' title='' tabindex='5' aria-labelledby='select2-cl_postal_code-container' data-toggle='tooltip' data-original-title='Por favor, selecciona un código postal' aria-owns='select2-cl_postal_code-results'><span class='select2-selection__rendered' id='select2-cl_postal_code-container' aria-label='NUEVO CLIENTE. Por favor, selecciona un código postal' title='15002'>15002</span><span class='select2-selection__arrow' role='presentation'><b role='presentation'></b></span></span></span><span class='dropdown-wrapper' aria-hidden='true'></span></span>\";" +
"document.getElementById(\"cl_postal_code\").value = \"15002\";" +
"$('.btn_new_client').click(); " +
"window.open('https://www.miweb.com/producto/?productID=6007020','_self');"+
"$('.price').text();").getJavaScriptResult().toString();
The javascript code what it does is set a postal code value, in this case '15002' and send the form. Then load the page of a product and return the price of that product, but in getJavaScriptResult () it returns null, to what is it due? Taking into account that this javascript code returns value for the last line when testing it to be executed on the browser's javascript console.