javascript - How to programmatically click on elements in Electron? - Stack Overflow

admin2025-04-17  0

I have an Electron application that relies on UI automation to play, pause, and skip from global-shortcut. On the website, I can use the jQuery .click() function and programmatically click on these elements. However, when the same site is embedded in Electron, the DOM changes - is there any way to click on specific elements from a webview in Electron?

Here's what Electron shows in source:

<body style="overflow:hidden;">
      <webview id="player" preload="./preload.js" src=" style="position:absolute;width:100%; height:100%" disablewebsecurity="" tabindex="-1"></webview> 
      <script>
      </script>
</body>

I have an Electron application that relies on UI automation to play, pause, and skip from global-shortcut. On the website, I can use the jQuery .click() function and programmatically click on these elements. However, when the same site is embedded in Electron, the DOM changes - is there any way to click on specific elements from a webview in Electron?

Here's what Electron shows in source:

<body style="overflow:hidden;">
      <webview id="player" preload="./preload.js" src="https://play.google. style="position:absolute;width:100%; height:100%" disablewebsecurity="" tabindex="-1"></webview> 
      <script>
      </script>
</body>
Share asked Jan 2, 2016 at 0:34 Niraj PantNiraj Pant 571 gold badge3 silver badges5 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 5

You can use jQuery. However, I urge you to move away from it and start realizing how powerful and similar vanilla JS, can be, making a stronger, lighter web app.

You can do this:

document.getElementById('player').click();

Keep in mind that anything you can do in a browser, you can also do in Electron!

On the website, I can use the jQuery .click() function

With electron you can also use jQuery exactly the same way.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744884864a272475.html

最新回复(0)