Setting value for input element in selenium Python












0















I am trying to change the value of an input tag element.



Here is the tag: <input type="hidden" id="hiRequestAccessType" data-bind="value: requestAccessTypeStr" value="2">



I want to change value to "2,1".



Based on discussion at Set value of input instead of sendKeys() - selenium webdriver nodejs, I tried using execute_script, but value remains unchanged.



I tried this:



passwordcheck_input_element = driver.find_element_by_xpath('//*[@id="hiRequestAccessType"]') . ###THIS DOESNT THROW ERRORS
new_value = "2,1"

driver.execute_script("arguments[0].value = arguments[1].toString()", passwordcheck_input_element, new_value)
# driver.execute_script("arguments[0].value = '" + new_value + "'", passwordcheck_input_element) . ###TRIED THIS IN LIEU OF ABOVE


For either alternative, code runs but value remains unchanged from visual inspection. I also tried the above two alternatives using 'setAttribute' instead of directly, same (no change) result.



Note that the webpage is a form where clicking on a check box changes value to "2,1" as desired. (But if I try finding the check box element, I get the message it is not clickable, hence this route).



Now, what's weird is I know it's doing something right behind the scenes because I tried querying value attribute before and after my execute_script call and it prints out the new value correctly for latter. However, as I said, the UI doesnt show this change; further, when I move on and hit the submit buttom further down, it's the old value that gets used because I am not getting the page that should load if the new value were used.










share|improve this question





























    0















    I am trying to change the value of an input tag element.



    Here is the tag: <input type="hidden" id="hiRequestAccessType" data-bind="value: requestAccessTypeStr" value="2">



    I want to change value to "2,1".



    Based on discussion at Set value of input instead of sendKeys() - selenium webdriver nodejs, I tried using execute_script, but value remains unchanged.



    I tried this:



    passwordcheck_input_element = driver.find_element_by_xpath('//*[@id="hiRequestAccessType"]') . ###THIS DOESNT THROW ERRORS
    new_value = "2,1"

    driver.execute_script("arguments[0].value = arguments[1].toString()", passwordcheck_input_element, new_value)
    # driver.execute_script("arguments[0].value = '" + new_value + "'", passwordcheck_input_element) . ###TRIED THIS IN LIEU OF ABOVE


    For either alternative, code runs but value remains unchanged from visual inspection. I also tried the above two alternatives using 'setAttribute' instead of directly, same (no change) result.



    Note that the webpage is a form where clicking on a check box changes value to "2,1" as desired. (But if I try finding the check box element, I get the message it is not clickable, hence this route).



    Now, what's weird is I know it's doing something right behind the scenes because I tried querying value attribute before and after my execute_script call and it prints out the new value correctly for latter. However, as I said, the UI doesnt show this change; further, when I move on and hit the submit buttom further down, it's the old value that gets used because I am not getting the page that should load if the new value were used.










    share|improve this question



























      0












      0








      0








      I am trying to change the value of an input tag element.



      Here is the tag: <input type="hidden" id="hiRequestAccessType" data-bind="value: requestAccessTypeStr" value="2">



      I want to change value to "2,1".



      Based on discussion at Set value of input instead of sendKeys() - selenium webdriver nodejs, I tried using execute_script, but value remains unchanged.



      I tried this:



      passwordcheck_input_element = driver.find_element_by_xpath('//*[@id="hiRequestAccessType"]') . ###THIS DOESNT THROW ERRORS
      new_value = "2,1"

      driver.execute_script("arguments[0].value = arguments[1].toString()", passwordcheck_input_element, new_value)
      # driver.execute_script("arguments[0].value = '" + new_value + "'", passwordcheck_input_element) . ###TRIED THIS IN LIEU OF ABOVE


      For either alternative, code runs but value remains unchanged from visual inspection. I also tried the above two alternatives using 'setAttribute' instead of directly, same (no change) result.



      Note that the webpage is a form where clicking on a check box changes value to "2,1" as desired. (But if I try finding the check box element, I get the message it is not clickable, hence this route).



      Now, what's weird is I know it's doing something right behind the scenes because I tried querying value attribute before and after my execute_script call and it prints out the new value correctly for latter. However, as I said, the UI doesnt show this change; further, when I move on and hit the submit buttom further down, it's the old value that gets used because I am not getting the page that should load if the new value were used.










      share|improve this question
















      I am trying to change the value of an input tag element.



      Here is the tag: <input type="hidden" id="hiRequestAccessType" data-bind="value: requestAccessTypeStr" value="2">



      I want to change value to "2,1".



      Based on discussion at Set value of input instead of sendKeys() - selenium webdriver nodejs, I tried using execute_script, but value remains unchanged.



      I tried this:



      passwordcheck_input_element = driver.find_element_by_xpath('//*[@id="hiRequestAccessType"]') . ###THIS DOESNT THROW ERRORS
      new_value = "2,1"

      driver.execute_script("arguments[0].value = arguments[1].toString()", passwordcheck_input_element, new_value)
      # driver.execute_script("arguments[0].value = '" + new_value + "'", passwordcheck_input_element) . ###TRIED THIS IN LIEU OF ABOVE


      For either alternative, code runs but value remains unchanged from visual inspection. I also tried the above two alternatives using 'setAttribute' instead of directly, same (no change) result.



      Note that the webpage is a form where clicking on a check box changes value to "2,1" as desired. (But if I try finding the check box element, I get the message it is not clickable, hence this route).



      Now, what's weird is I know it's doing something right behind the scenes because I tried querying value attribute before and after my execute_script call and it prints out the new value correctly for latter. However, as I said, the UI doesnt show this change; further, when I move on and hit the submit buttom further down, it's the old value that gets used because I am not getting the page that should load if the new value were used.







      python selenium input






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 21:12







      Titanical

















      asked Jan 1 at 20:47









      TitanicalTitanical

      206




      206
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Could you please try the code below?



          passwordcheck_input_element = driver.find_element_by_id("hiRequestAccessType")
          driver.execute_script("arguments[0].value = '2,1';", passwordcheck_input_element)


          You can also control the checkbox object via javascript execution if it is not clickable.



          driver.execute_script("document.getElementById('hiRequestAccessType').checked = true;")





          share|improve this answer

































            0














            driver.find_element_by_xpath('//*[@id="hiRequestAccessType"]').setAttribute("value", "1")



            Short you can select with xpath or css name element after selection you can change with .setAttribute function your value. Also you can get current selected element value with getAttribute function.For simulate checkbox click : .setAttribute("checked", "checked")






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998819%2fsetting-value-for-input-element-in-selenium-python%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Could you please try the code below?



              passwordcheck_input_element = driver.find_element_by_id("hiRequestAccessType")
              driver.execute_script("arguments[0].value = '2,1';", passwordcheck_input_element)


              You can also control the checkbox object via javascript execution if it is not clickable.



              driver.execute_script("document.getElementById('hiRequestAccessType').checked = true;")





              share|improve this answer






























                0














                Could you please try the code below?



                passwordcheck_input_element = driver.find_element_by_id("hiRequestAccessType")
                driver.execute_script("arguments[0].value = '2,1';", passwordcheck_input_element)


                You can also control the checkbox object via javascript execution if it is not clickable.



                driver.execute_script("document.getElementById('hiRequestAccessType').checked = true;")





                share|improve this answer




























                  0












                  0








                  0







                  Could you please try the code below?



                  passwordcheck_input_element = driver.find_element_by_id("hiRequestAccessType")
                  driver.execute_script("arguments[0].value = '2,1';", passwordcheck_input_element)


                  You can also control the checkbox object via javascript execution if it is not clickable.



                  driver.execute_script("document.getElementById('hiRequestAccessType').checked = true;")





                  share|improve this answer















                  Could you please try the code below?



                  passwordcheck_input_element = driver.find_element_by_id("hiRequestAccessType")
                  driver.execute_script("arguments[0].value = '2,1';", passwordcheck_input_element)


                  You can also control the checkbox object via javascript execution if it is not clickable.



                  driver.execute_script("document.getElementById('hiRequestAccessType').checked = true;")






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 1 at 21:30

























                  answered Jan 1 at 21:22









                  Recep DumanRecep Duman

                  838




                  838

























                      0














                      driver.find_element_by_xpath('//*[@id="hiRequestAccessType"]').setAttribute("value", "1")



                      Short you can select with xpath or css name element after selection you can change with .setAttribute function your value. Also you can get current selected element value with getAttribute function.For simulate checkbox click : .setAttribute("checked", "checked")






                      share|improve this answer




























                        0














                        driver.find_element_by_xpath('//*[@id="hiRequestAccessType"]').setAttribute("value", "1")



                        Short you can select with xpath or css name element after selection you can change with .setAttribute function your value. Also you can get current selected element value with getAttribute function.For simulate checkbox click : .setAttribute("checked", "checked")






                        share|improve this answer


























                          0












                          0








                          0







                          driver.find_element_by_xpath('//*[@id="hiRequestAccessType"]').setAttribute("value", "1")



                          Short you can select with xpath or css name element after selection you can change with .setAttribute function your value. Also you can get current selected element value with getAttribute function.For simulate checkbox click : .setAttribute("checked", "checked")






                          share|improve this answer













                          driver.find_element_by_xpath('//*[@id="hiRequestAccessType"]').setAttribute("value", "1")



                          Short you can select with xpath or css name element after selection you can change with .setAttribute function your value. Also you can get current selected element value with getAttribute function.For simulate checkbox click : .setAttribute("checked", "checked")







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 2 at 1:29









                          ServooServoo

                          1




                          1






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998819%2fsetting-value-for-input-element-in-selenium-python%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                              Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

                              A Topological Invariant for $pi_3(U(n))$