0

im trying to automate some of my work I have to do every day which involves clicking a bunch of buttons sequentially.

I wrote a script and it has stopped working through a chrome extension.

I'm using the keypress library (https://dmauro.github.io/Keypress/) in a chrome extension to string together button clicks

ie - press "down", triggers clicking button 1, etc

Is it possible for a website to disable a chrome extension performing .click() on a button?

Some buttons on the page respond to my script simulating a .click() event, while others do not. I cannot figure out why

for example:

enter image description here

I'm trying to click the button nested under the div. I can access it with $('#ember8628')[0].click() but nothing happens.

When I click on it on the page, it works as expected.

To make sure I'm executing .click() on what I'm expecting to, I'm hovering over the readout in the dev tools when running $('#ember8628')[0]

Can you spot anything I'm doing wrong?

Morgan Allen
  • 3,291
  • 8
  • 62
  • 86
  • 2
    Can you expand on what the question is? There's no such thing as `CSS_Selector.click()`, so I'm not sure what you are asking. You can have JS trigger a click event, if you have an element reference. `document.querySelector('#ember8628').click()`. – Kelderic Sep 15 '20 at 16:19
  • 3
    A website can ignore programmatic clicks, yes. User-initiated clicks are flagged as "trusted". See [Detect Whether an Event is Triggered by User and not programmatically](https://stackoverflow.com/q/29798010/215552) – Heretic Monkey Sep 15 '20 at 16:20
  • @HereticMonkey, to be clear here, any javascript that is running on a website can tell if a click event has been trigger programatically or instead by user action, and can then choose to take action or not take action depending on that. The event isn't being ignored. It can just be responded to in different ways depending on if the event is programatic. – Kelderic Sep 15 '20 at 16:24
  • I was using CSS_Selector as a template name for any CSS selector I can use to find the element on the page I want to click – Morgan Allen Sep 15 '20 at 16:29
  • @AndyMercer Potayto, potahto. The end result of the event response in the case of programmatic clicks is that the click event does nothing. I call that "ignoring" the event, just like when you have an empty catch in a try/catch, I call that "ignoring" the error/exception. I'm not wrong, I'm just using the word differently from you. – Heretic Monkey Sep 15 '20 at 16:34
  • this is super helpful. I take it there isn't a way around it? – Morgan Allen Sep 15 '20 at 16:37
  • *I wrote a script and it has stopped working through a chrome extension.* - do you mean: "I wrote a script through a chrome extension and it has stopped working"? – freedomn-m Sep 15 '20 at 16:39
  • Unlikely, but worth a try: What does `console.log($('[id=ember8628]').length)` give you? Could be if there's multiple elements with the same id then you're picking the wrong one? – freedomn-m Sep 15 '20 at 16:42
  • It could be that your element doesn't have a `click()` event handler - if they're using `mouseup()` to "simulate" a click. – freedomn-m Sep 15 '20 at 16:43
  • thats super interesting! Is there a way to see what the event handlers are on a button? – Morgan Allen Sep 15 '20 at 16:59
  • the length is 1 – Morgan Allen Sep 15 '20 at 17:00
  • Could be the site has changed how page is created such as dynamically inserting elements client side that previously were inserted server side making the timing of when you run your code more critical – charlietfl Sep 15 '20 at 17:00
  • @charlietfl at this point im just trying to click the first button on the page and see if I get any response from the browser. unfortunately nothing is happening – Morgan Allen Sep 15 '20 at 17:01
  • ...so I take it my code *did* work on Chrome...? –  Sep 17 '20 at 13:55

0 Answers0