This repository has been archived by the owner. It is now read-only.

dom is reloaded #13886

Closed
kxjhcs opened this Issue Jan 13, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@kxjhcs

kxjhcs commented Jan 13, 2016

my test url is http://localhost:8088/;
Web page source code:

<!doctype html>
<html lang="en">
<body>
<a href="http://localhost:8088/"&gt;test&lt;/a>
<input type='text'></input>
</body>
</html>

i am query all elements and simluate click one by one.
when one element is clicked , i will marked it , element.setAttribute('mark', 'clicked');
but when i clicked the "<a href="http://localhost:8088/"&gt;test&lt;/a>", the dom is reload,
what i mark is lost, is it right?

@awakmu

This comment has been minimized.

Show comment
Hide comment
@awakmu

awakmu Jan 14, 2016

I can't find "element.setAttribute" on your code.
Please post an error reproducible code.

awakmu commented Jan 14, 2016

I can't find "element.setAttribute" on your code.
Please post an error reproducible code.

@kxjhcs

This comment has been minimized.

Show comment
Hide comment
@kxjhcs

kxjhcs Jan 14, 2016

this is my test script:

var page = require('webpage').create();
var loadFinsihed = false;
var clickCount = 0;
var requestCount = 0;
var navigationCount = 0;
page.onConsoleMessage = function (msg) {
console.log(msg);
};
page.onResourceRequested = function (requestData, networkRequest) 
{
 console.log((++requestCount).toString() + " onResourceRequested:" +    requestData.url);
    if(loadFinsihed)
        networkRequest.abort();
};
page.onNavigationRequested = function(url, type, willNavigate, main){
    console.log((++navigationCount).toString() + " onNavigationRequested:" + url)
}
page.onLoadFinished = function (status) 
{
    page.evaluate(function () {
        console.log(document.body.outerHTML);

        var ele = document.body.querySelector('a');
        ele.setAttribute('crawl_mark', 'staged');
        var event = document.createEvent("MouseEvents");
        event.initMouseEvent("click", true, true, window, 0, 0, 0, 0 ,0, false, false, false, false, 0, null);
        ele.dispatchEvent(event);
    });
    loadFinsihed = true;
    ++clickCount;
    if(clickCount >= 2)
        phantom.exit();
}

page.open("http://localhost:8088/", function (status) { 
});

run result:

1 onNavigationRequested:http://localhost:8088/
1 onResourceRequested:http://localhost:8088/
<body>
    <a href="http://localhost:8088/">test</a>
    <input type="text">

</body>
2 onNavigationRequested:http://localhost:8088/
<body>
    <a href="http://localhost:8088/">test</a>
    <input type="text">

</body>
3 onNavigationRequested:http://localhost:8088/

"onResourceRequested" just called once,and the attribute what i set is lost,

kxjhcs commented Jan 14, 2016

this is my test script:

var page = require('webpage').create();
var loadFinsihed = false;
var clickCount = 0;
var requestCount = 0;
var navigationCount = 0;
page.onConsoleMessage = function (msg) {
console.log(msg);
};
page.onResourceRequested = function (requestData, networkRequest) 
{
 console.log((++requestCount).toString() + " onResourceRequested:" +    requestData.url);
    if(loadFinsihed)
        networkRequest.abort();
};
page.onNavigationRequested = function(url, type, willNavigate, main){
    console.log((++navigationCount).toString() + " onNavigationRequested:" + url)
}
page.onLoadFinished = function (status) 
{
    page.evaluate(function () {
        console.log(document.body.outerHTML);

        var ele = document.body.querySelector('a');
        ele.setAttribute('crawl_mark', 'staged');
        var event = document.createEvent("MouseEvents");
        event.initMouseEvent("click", true, true, window, 0, 0, 0, 0 ,0, false, false, false, false, 0, null);
        ele.dispatchEvent(event);
    });
    loadFinsihed = true;
    ++clickCount;
    if(clickCount >= 2)
        phantom.exit();
}

page.open("http://localhost:8088/", function (status) { 
});

run result:

1 onNavigationRequested:http://localhost:8088/
1 onResourceRequested:http://localhost:8088/
<body>
    <a href="http://localhost:8088/">test</a>
    <input type="text">

</body>
2 onNavigationRequested:http://localhost:8088/
<body>
    <a href="http://localhost:8088/">test</a>
    <input type="text">

</body>
3 onNavigationRequested:http://localhost:8088/

"onResourceRequested" just called once,and the attribute what i set is lost,

@Vitallium

This comment has been minimized.

Show comment
Hide comment
@Vitallium

Vitallium Jan 14, 2016

Collaborator

Thank you for submitting this ticket!

This issue tracker primarily serves as the tool to report and track bugs, defects, and development tasks.
For general question, code review request, build problem, or other related discussion, please post it to either:

If you have not read it yet, please check also a few tips on Effective Q&A.

Collaborator

Vitallium commented Jan 14, 2016

Thank you for submitting this ticket!

This issue tracker primarily serves as the tool to report and track bugs, defects, and development tasks.
For general question, code review request, build problem, or other related discussion, please post it to either:

If you have not read it yet, please check also a few tips on Effective Q&A.

@Vitallium Vitallium closed this Jan 14, 2016

@kxjhcs

This comment has been minimized.

Show comment
Hide comment
@kxjhcs

kxjhcs commented Jan 15, 2016

thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.