Problem resolved.
This one, code below, works, seems can not call a method with parameter in window.onload directly.
When call method with parameter in window.onload, it will execute this method before window.onload, so the element didn't complete loading when the method is executing, so it will return null.
function testClickWithParam(xpath){
var e = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null).iterateNext();
if(document.createEvent){
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, false);
e.dispatchEvent(event);
}
else if(document.createEventObject){
e.fireEvent('onclick');
}
}
function testClickLink(){
var xpath = "(//a[@href='./detail.html'])[1]";
console.log(window.location.href);
testClickWithParam(xpath);
}
window.onload = testClickLink;