how to programatically click a button thats loaded from another page?

瘦欲@ 提交于 2019-12-06 16:28:53

One way;

<script type="text/javascript">
function doClick(fr) {
    var btn = fr.contentWindow.document.getElementsByName("SUBMIT-password.pss");
    if (btn.length === 0) {
        alert("no button!");
        return;
    } else {
        btn[0].click();
    }
}
</script>
<frameset rows="60px, *"> 
    <frame src="topo.htm" name="topo" id="topo" application="yes" /> 
    <frame src="http://localhost/nph-psf.exe?HOSTID=AD&ALIAS=" name="conteudo" id="psyncLink" application="yes" onload="doClick(this);"/> 
    </frameset> 
</html> 

You can try this javascript. Since the element doesn't have an ID we have to grab it by Name which returns an array. You can also get by tagname but I wasn't sure how many inputs there would be on the other page.

try{
     window.frames[1].document.getElementsByName('SUBMIT-password.pss')[0].click();
}catch(Exception){
    alert('hi');
}

If you have access to the page that you are loading you can simulate a click on the button. The easiest way to do this I think is jQuery click. Check this: http://api.jquery.com/click/.

Add a small script at the end of the page that clicks it and should be ok.

If you don't have access... You can still manipulate the dom to select the button and click it if the page is loaded in an iframe but would be a bit harder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!