Input value returns empty string on JS log











up vote
0
down vote

favorite












I am trying to do a simple webpage interaction from an android app with JavaScript. Here is the problem: I could fill the text input place with changing value of the corresponding text input field with JavaScript. However, when I click the button (which should evaluate the information from the text input field), the value of the text input field appears as an empty string.



Any kind of user interaction(eg. putting a space to the end of the string and deleting it) turns everything to normal. However, since I am trying to automate the whole process, it is not an option.



The code I am using for filling the text input field is very similar to this code:



String username = "cristian";
webview.loadUrl("javascript:document.getElementById('username').value = '"+username+"';");


And the way I call it:



webView.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
if(consoleMessage.message().contains("DEPRECATED")){
tester.setValueForItemWithId("comp-jo5fnli5input", loginInfo);
tester.clickOnItemWithClassName("b4label", 0);
}
if(consoleMessage.message().contains("User is logged in")) {
Toast.makeText(getBaseContext(), consoleMessage.message(), Toast.LENGTH_LONG).show();
}
return true;
}
});


I don't think immediate clicking of the button is causing the problem, because I tried to pressing the button manually too and got the same result.



I am waiting for your answers. Please point out if some part of the question is hard to understand.



Have a nice day.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am trying to do a simple webpage interaction from an android app with JavaScript. Here is the problem: I could fill the text input place with changing value of the corresponding text input field with JavaScript. However, when I click the button (which should evaluate the information from the text input field), the value of the text input field appears as an empty string.



    Any kind of user interaction(eg. putting a space to the end of the string and deleting it) turns everything to normal. However, since I am trying to automate the whole process, it is not an option.



    The code I am using for filling the text input field is very similar to this code:



    String username = "cristian";
    webview.loadUrl("javascript:document.getElementById('username').value = '"+username+"';");


    And the way I call it:



    webView.setWebChromeClient(new WebChromeClient(){
    @Override
    public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
    if(consoleMessage.message().contains("DEPRECATED")){
    tester.setValueForItemWithId("comp-jo5fnli5input", loginInfo);
    tester.clickOnItemWithClassName("b4label", 0);
    }
    if(consoleMessage.message().contains("User is logged in")) {
    Toast.makeText(getBaseContext(), consoleMessage.message(), Toast.LENGTH_LONG).show();
    }
    return true;
    }
    });


    I don't think immediate clicking of the button is causing the problem, because I tried to pressing the button manually too and got the same result.



    I am waiting for your answers. Please point out if some part of the question is hard to understand.



    Have a nice day.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to do a simple webpage interaction from an android app with JavaScript. Here is the problem: I could fill the text input place with changing value of the corresponding text input field with JavaScript. However, when I click the button (which should evaluate the information from the text input field), the value of the text input field appears as an empty string.



      Any kind of user interaction(eg. putting a space to the end of the string and deleting it) turns everything to normal. However, since I am trying to automate the whole process, it is not an option.



      The code I am using for filling the text input field is very similar to this code:



      String username = "cristian";
      webview.loadUrl("javascript:document.getElementById('username').value = '"+username+"';");


      And the way I call it:



      webView.setWebChromeClient(new WebChromeClient(){
      @Override
      public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
      if(consoleMessage.message().contains("DEPRECATED")){
      tester.setValueForItemWithId("comp-jo5fnli5input", loginInfo);
      tester.clickOnItemWithClassName("b4label", 0);
      }
      if(consoleMessage.message().contains("User is logged in")) {
      Toast.makeText(getBaseContext(), consoleMessage.message(), Toast.LENGTH_LONG).show();
      }
      return true;
      }
      });


      I don't think immediate clicking of the button is causing the problem, because I tried to pressing the button manually too and got the same result.



      I am waiting for your answers. Please point out if some part of the question is hard to understand.



      Have a nice day.










      share|improve this question















      I am trying to do a simple webpage interaction from an android app with JavaScript. Here is the problem: I could fill the text input place with changing value of the corresponding text input field with JavaScript. However, when I click the button (which should evaluate the information from the text input field), the value of the text input field appears as an empty string.



      Any kind of user interaction(eg. putting a space to the end of the string and deleting it) turns everything to normal. However, since I am trying to automate the whole process, it is not an option.



      The code I am using for filling the text input field is very similar to this code:



      String username = "cristian";
      webview.loadUrl("javascript:document.getElementById('username').value = '"+username+"';");


      And the way I call it:



      webView.setWebChromeClient(new WebChromeClient(){
      @Override
      public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
      if(consoleMessage.message().contains("DEPRECATED")){
      tester.setValueForItemWithId("comp-jo5fnli5input", loginInfo);
      tester.clickOnItemWithClassName("b4label", 0);
      }
      if(consoleMessage.message().contains("User is logged in")) {
      Toast.makeText(getBaseContext(), consoleMessage.message(), Toast.LENGTH_LONG).show();
      }
      return true;
      }
      });


      I don't think immediate clicking of the button is causing the problem, because I tried to pressing the button manually too and got the same result.



      I am waiting for your answers. Please point out if some part of the question is hard to understand.



      Have a nice day.







      javascript android webview interaction wixcode






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 7 at 17:45









      Bob Arnson

      17.7k22936




      17.7k22936










      asked Nov 7 at 7:56









      Furkan Küçük

      469




      469





























          active

          oldest

          votes











          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',
          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%2f53185425%2finput-value-returns-empty-string-on-js-log%23new-answer', 'question_page');
          }
          );

          Post as a guest





































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185425%2finput-value-returns-empty-string-on-js-log%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings