Javascript XPath无法从Greasemonkey脚本中单击按钮
我想打开一个包含单词Javascript XPath无法从Greasemonkey脚本中单击按钮,javascript,button,xpath,click,greasemonkey,Javascript,Button,Xpath,Click,Greasemonkey,我想打开一个包含单词google的链接。看起来是这样的: <input class="submit" style="background: #409999; border-radius: 10px;" value="open" onclick="Open('143615', '1', 'https://www.google.de/');" type="submit"> 它没有效果。我想通过Greasemonkey打开窗口(单击事件?) 当我使用alert(elm.href)时它说
google
的链接。看起来是这样的:
<input class="submit" style="background: #409999; border-radius: 10px;" value="open" onclick="Open('143615', '1', 'https://www.google.de/');" type="submit">
它没有效果。我想通过Greasemonkey打开窗口(单击事件?)
当我使用
alert(elm.href)时代码>它说它是“未定义的”。但是当我在FirePath中尝试XPath时,XPath可以工作。你说XPath可以工作,但是elm.href
在GM脚本中没有定义。这表明
是通过AJAX添加的
您的脚本需要使用。比如:
// ==UserScript==
// @name _Clicking "Open" buttons
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
waitForKeyElements ("input.submit[onclick*='open']", clickOpenBtn);
function clickOpenBtn (jNode) {
triggerMouseEvent (jNode[0], "click");
}
function triggerMouseEvent (node, eventType) {
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent (eventType, true, true);
node.dispatchEvent (clickEvent);
}
您说XPath可以工作,但是GM脚本中未定义elm.href
。这表明
是通过AJAX添加的
您的脚本需要使用。比如:
// ==UserScript==
// @name _Clicking "Open" buttons
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
waitForKeyElements ("input.submit[onclick*='open']", clickOpenBtn);
function clickOpenBtn (jNode) {
triggerMouseEvent (jNode[0], "click");
}
function triggerMouseEvent (node, eventType) {
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent (eventType, true, true);
node.dispatchEvent (clickEvent);
}