<a class="js-open-panel action-button" target="video-download" href="#">
<em><span class="icon-16x16 icon-download"></span> Download</em></a>使用firebug的xpath /html/body/div2/div2/section3/a4
我想单击此按钮,但始终没有任何东西工作“”getElementBy“
我通过搜索读了一本很大的书,但什么都没有用。
/*
function clickc(x)
{
var el = document.getElementsByTagName('em')[7];
var evt = document.createEvent("MouseEvents");
evt.initEvent("click", true, true);
el.dispatchEvent(evt);
}
setTimeout (clickc , 1);
*/
/*
document.getElementsByClassName("js-open-panel action-button").click();
*/
/*
function clickc(x)
{
var x = document.getElementsByTagName('em')[7].click();
click(x);
}
setTimeout (clickc , 1);
*/发布于 2013-01-04 15:55:08
只要AJAX未加载该按钮,就应该可以执行以下操作:
var dwnldBttn = document.querySelector (
"a.js-open-panel.action-button[target='video-download']"
);
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
dwnldBttn.dispatchEvent (clickEvent);请注意,querySelector()的工作依赖于CSS选择器( Firebug也会显示)而不是XPath。
从评论中可以看出,AJAX似乎没有加载这个按钮(但它可能被用来激活它)。
使用这个完整的脚本开始。除了@include指令之外,不做任何更改。
// ==UserScript==
// @name _YOUR_SCRIPT_NAME
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
setTimeout (clickDownloadButton, 1111);
function clickDownloadButton () {
var dwnldBttn = document.querySelector (
"a.js-open-panel.action-button[target='video-download']"
);
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
dwnldBttn.dispatchEvent (clickEvent);
}https://stackoverflow.com/questions/14152525
复制相似问题