0

So I'm trying to make a chrome extension for a forum and right now I'm stuck at the necessary confirm after pressing the delete-button.

I want to press the confirm-button but as far as I understand I have to find it first - for this I have the content-script. But now I dont know how to find the right element, I just dont know how to identify the button.

This is the Code on the Webpage:

<td class="confirmButtons">
<form action="modcp.php" method="post">
<input class="formAction" type="hidden" name="" value="">
<ul>
<li class="button"><a href="javascript:void(0);" class="formAction" rel="confirm" tabindex="2"><strong>Ja</strong></a></li>
</ul>

<ul class="buttonGroup">
<li class="first"></li>
<li class="button"><a href="javascript:void(0);" class="formAction" rel="cancel" tabindex="2"><strong>Nein</strong></a></li><a href="javascript:void(0);" class="formAction" rel="cancel" tabindex="2">
<li class="last"></li>
</a></ul><a href="javascript:void(0);" class="formAction" rel="cancel" tabindex="2">
</a></form></td>

The Code I have in the content_script so far:

function clickJa() {
var confirmButtoon = document.getElementsByClass("form-action");

confirmButton.click();
}

clickJa();

I know this doesnt work but I dont know what do do...

Thanks for every piece of help, greetings =)

  • 1
    Try `dispatchEvent`: [How do I programmatically click on an element?](//stackoverflow.com/a/22469115) – wOxxOm Mar 09 '17 at 17:04
  • 1
    Typo? getElementsByClass**Name** returns an array so you need to index it `confirmButton[0]` – wOxxOm Mar 09 '17 at 17:10
  • To clearify this: My biggest problem is to FIND the right element, since it doesnt have an ID - is there a way to find it by rel="confirm" – Morality Lime Mar 09 '17 at 17:13
  • 1
    Read about CSS selectors and use `document.querySelector('[rel="confirm"]')` – wOxxOm Mar 09 '17 at 17:14
  • There is no such `class` as `form-action` in the HTML provided. Perhaps, you meant `formAction`. Note: this does not actually solve your problem, but at least finds something. See wOxxOm's comment above about using `.querySelector()`. Depending on what else is on the page, you may need a more complex selector. However, the more complex the selector, the more dependent it is on the actual HTML code for the page (and more likely it will break if the HTML changes). The best option is to see what the JavaScript on the page uses to differentiate between the buttons and use the same selector. – Makyen Mar 09 '17 at 17:45
  • What *exactly* is shown in the [various appropriate consoles for your extension](http://stackoverflow.com/a/38920982/3773011) when you load and execute your extension? There will be an error in the console which would have pointed you in the direction of your current problems. In addition, using the debugger would have helped you identify the problem. I suggest you become familiar with looking in the console and using the debugger. – Makyen Mar 09 '17 at 17:47

0 Answers0