Fill web forms from Chrome console

0

I have a web form that I have to fill in from the "Chrome" console. In the text boxes I have no problems. Use for example:

txtNombre.value='nombre';

But in the list boxes of select I do not know how I can select an option from the console. How would it be in this case? this is the code:

    <tr>
    <td>Gender</td>
    <td>
        <div class="select2-container" id="s2id_ContentPlaceHolder1_personDetails_genderDropDownList">
    <a href="javascript:void(0)" class="select2-choice select2-default select2-required" tabindex="-1">   
    <span class="select2-chosen" id="select2-chosen-2">Select an Option</span>
    <abbr class="select2-search-choice-close"></abbr>   <span class="select2-arrow" role="presentation">
    <b role="presentation"></b></span></a><label for="s2id_autogen2" class="select2-offscreen"></label>
    <input class="select2-focusser select2-offscreen" type="text" aria-haspopup="true" role="button" aria-labelledby="select2-chosen-2" id="s2id_autogen2" tabindex="0"></div>
    <select name="_ctl0:ContentPlaceHolder1:personDetails:genderDropDownList" id="ContentPlaceHolder1_personDetails_genderDropDownList" onchange="nzis.UpdateDropdownErrorLabel(this)" errorlabel="mandatory" tabindex="-1" title="" style="display: none;">
        <option selected="selected" value=""></option>
        <option value="M">Male</option>
        <option value="F">Female</option>

    </select>

    </td>
</tr>

from the chrome console you should be able to put the Male option in the Gender box.

    
asked by Marcos Restelli 18.08.2017 в 17:35
source

1 answer

0

You can write this in the console

document.getElementById("download-document").value = "book";

In this case I did it in the official Symfony page

In the Offline Documentation section there are two selections, the first is where I change the value. If you do not want to check in that url, you just have to replace the passed parameter in getElementById with the id of the select that you want to change its value and assign it the value of the value property of one of its options.

for example, suppose you have a page that has this form

<select name="paises" id="paises_select">
  <option>Seleccione un pais</option>
  <option value="ES">España</option>
  <option value="EU">Estados Unidos</option>
  <option value="BR">Brasil</option>
</select>

And let's say you want to select Spain, because you can do one of the following two options

document.getElementById("paises_select").value = "ES";

OR

//Si estuviera dentro de un formulario llamado form1 sería form.paises.value = "ES" sino
paises.value = "ES";
    
answered by 18.08.2017 в 20:33