Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to go to a page, click a button and then get it's DOM
    primarykey
    data
    text
    <p>I am writing a script in javascript/jquery that once executed must go a sub-page, click on a button and then get the DOM of that resulting page. After which I can just do some manipulation and get some needed data. </p> <p>After some digging around I wrote this script: </p> <pre><code>var pageDOM = null; var xhr = new XMLHttpRequest(); xhr.overrideMimeType('text/xml'); xhr.open('GET', '/newsfeed-simulator', true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { pageDOM = xhr.responseXML; pageDOM.getElementById("simulate-button").click(); } }; xhr.send(null); </code></pre> <p>With this script, I can access the required sub-page but xhr.responseXML always returns null. I googled and added <code>xhr.overrideMimeType('text/xml');</code> but it still doesn't work. The weird thing is that <code>xhr.responseText;</code> works fine.</p> <p>Not sure whats wrong, it should be a straight forward task? Any ideas/comments/suggestions on how to fix this problem?</p> <p>Best,</p> <p>P.S.: It's first post here, so hi :D</p> <p><strong>EDIT1</strong> newsfeed-simulator is basically a page with a button that I need to click. Once clicked the page is loaded with elements, which then I can use to get some data. </p> <p><strong>EDIT2</strong> After a few hours of googling I came up with this</p> <pre><code>var xhr = new XMLHttpRequest(); xhr.open('GET', '/newsfeed-simulator', true); xhr.responseType = 'document'; xhr.onload = function(e) { if (this.status == 200) { console.log(xhr.response) xhr.response.getElementById("simulate-button").click(); console.log(xhr.response.body) } }; xhr.send(); </code></pre> <p>Using XMLHttpRequest2 I can now get the source easily (as a document and not a text) and not get a null. Problem is (as charlietfl hinted) <code>xhr.response.getElementById("simulate-button").click();</code>is not working correctly. I.E. I am getting the body of the DOM without the button being clicked on. Any ideas how can I simulate a mouseClick, cuz my way is not working?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload