-2

I'm trying to get response of GET request, that starts after document.getElementById('btnPdf').click();

I'm using Selenium Webdriver as JavaScriptExecutor.

My question is similar to this How do I capture response of form.submit but I don't know exact url and would prefer to use pure JS without AJAX (if it's possible).

Community
  • 1
  • 1
  • That is possible, probably, the question is just a little vague. Please clarify what exactly you want to do. When you say "pure js without ajax" do you specifically mean jQuery.ajax? because "ajax" is a technique. – rlemon Nov 07 '16 at 15:09
  • That's only because I use JavaScriptExecutor instead of usual browser. I appreciate any help using any technique. – Grigorii Alekseev Nov 07 '16 at 17:27

1 Answers1

-1

function get

Response() {
      var send1='senddata'; // this is a var to send
      var send2='senddata2'; // this is another var to send
      var xhr = new XMLHttpRequest();
      xhr.open('POST', 'myGetPageName',true);
      xhr.setRequestHeader('Content-Type', 'text/plain');
      xhr.onload = function() {
          if (xhr.status === 200) {
              var myResponse = xhr.responseText;
              alert(myResponse);
          }
      };
      xhr.send('myvar1=' + send1 + '&myvar2=' + send2)
}
  • I don't understand how it solves my problem. I don't know url, just click the button and want to catch response – Grigorii Alekseev Nov 07 '16 at 17:32
  • You can't post or get from a mystery URL. Sound like your using someone else's script and you won't get a response as a var unless they wrote it that way. – Robert Harrison Nov 08 '16 at 13:18