I remember two more ways to click a button besides the one you mentioned.
First is using jQuery
Code:
$('[name="elementname"]').click();
It doesnt always work on GM, but it should if you add this at the top:
Code:
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
Also looking for it by tags like this:
Code:
document.getElementsByClassName("classname")[0].getElementsByTagName("form")[0].getElementsByTagName("input")[0].click();
I dont know how to close a tab though, never done it before...
--
Oh, i just remembered another one, if the button is in a form, something like this should work:
Code:
document.forms.giveform.submit();