Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening and closing a WebDriver from the EEL GUI. #602

Closed
maximedrn opened this issue Aug 4, 2022 · 2 comments
Closed

Opening and closing a WebDriver from the EEL GUI. #602

maximedrn opened this issue Aug 4, 2022 · 2 comments

Comments

@maximedrn
Copy link

maximedrn commented Aug 4, 2022

Hello,
As the title says, I am trying to make a GUI with a simple button to start and close a WebDriver. When it is open, the WebdDriver performs some tasks for an indefinite time. When the user wants to stop the process, he just clicks on the button to close it and return to the GUI.

I've read a few issues and Stackoverflow pages on similar topics, but none of them helped me in this case.

Here is the code I use, I removed the part about multiprocessing/threading/pool because none of them work.

main.py

#!usr/bin/python

import eel

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as SC
from webdriver_manager.chrome import ChromeDriverManager as CDM


@eel.expose
def open():
    """Open the webdriver in a parallel process."""


def web():
    global driver
    driver = webdriver.Chrome(service=SC(CDM(log_level=0).install()))
    # Does its tasks.


@eel.expose
def close():
    """Stop the webdriver from the parallel process."""


if __name__ == '__main__':
    eel.init('.')
    eel.start('index.html')

index.html

<!DOCTYPE html>

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script type="text/javascript" src="/eel.js"></script>
        <script>
            let isRunning = false;
            function webdriver() {
                isRunning ? eel.close() : eel.open();
                isRunning = !isRunning;
            }
        </script>
    </head>

    <body>
        <button onclick="webdriver()">Webdriver</button>
    </body>
</html>

The files are in the same directory.
I'm using Windows 11 with the latest version of the ChromeDriver and the latest version of the eel module on Python 3.9.9.

@dardevelin
Copy link

Disclaimer:
I have no used the project extensively enough to be able to advise with confidence.
All tips in here are just attempts at providing some pointers since I saw that the project is semi-abandoned
as per this GitHub issue: #600

Assumptions

    • eel behaves somewhat a little like selenium in that the web driver is not a python process
    • eel has an event loop which keeps the application running
    • eel has interrupt mechanism for functions that are being called from javascript/browser side

First Idea
Use psutil python module to kill the new instance/window and kill it when done. trap the exception in python code.
not clean but might get you there.

Considerations:
Based on point 1, it would mean that stopping a full window may not be possible without 'killing' the driver.
If it's like selenium, doing so would destroy all instances of eel or the browser at once, making my first idea no viable.

Second Idea
Once again assuming it's like selenium you might be able to create a new 'tab' in the browser, which you can also detach.
The important part is that by doing so you would be retaining independent control of each "window" and effectively be able to easily kill it using regular eel controls.

How would you be able to monitor once detached I don't know, maybe via a sub-process...

I hope any of this helps.
Happy Hacking

@maximedrn
Copy link
Author

Hello, thank you for you answer :) I tried the first option and it works great.
I used the terminate() method to stop the process and then I kill all the processes of the webdriver using psutil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants