问题
I'm a bit stuck. I'm trying to create an Grease Monkey script that will automatically click an pop-up that appears on an auction site. I'v got the Xpat, but i'm too in expierienced with GM to get it to work.
Here is theelement inspection line i get from fire finder for firebug:
<input type="submit" style="width: 160px;" class="simplemodal-close" id="ctl00_mainContentPlaceholder_Button3" onclick="closePopup(); return false;" value="Back To Auctions" name="ctl00$mainContentPlaceholder$Button3">
and the firpath, xpath line is:
.//*[@id='ctl00_mainContentPlaceholder_Button3']
xpather line for full xpath:
/html/body/form[@id='aspnetForm']/div[@id='simplemodal-container']/div/div[@id='basic-modal-content']/div[@id='modal_winningBanner']/div/div[2]/div[2]/input[@id='ctl00_mainContentPlaceholder_Button3']
So what i used in my gm script to try to get it to click the button is as follows:
// @include *
// @version 0.1
// @description Automatically click // ==/UserScript==
click_popupBtn1 = function() {
var joinBtn=document.evaluate('//*[@id, "ctl00_mainContentPlaceholder_Button3"]'
,document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null).singleNodeValue.click();
alert(joinBtn);
if(!joinBtn) return false;
joinBtn.click();
return true;
}
click_popupBtn1 ();
I think ive got something wrong on the syntax, but dont know how to debug GM. I've only worked with turbo pascal a few years ago, but would like to get some simple things done in java and GM.
Any help would be apreciated.
Thanks Ludwig
回答1:
umm, I don't understand a lot of the words you used or this complex syntax.
but something like:
document.getElementById("ctl00_mainContentPlaceholder_Button3").click();
should work.
回答2:
var joinBtn=document.evaluate('//*[@id, "ctl00_mainContentPlaceholder_Button3"]' ,document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).singleNodeValue.click();
The first argument above is not a syntactically legal XPath expression.
Should be:
//*[@id = "ctl00_mainContentPlaceholder_Button3"]
来源:https://stackoverflow.com/questions/6077020/need-to-click-a-bid-button-with-grease-monkey-script