简体   繁体   中英

How to connect Python Selenium with Electron JS App

I'm building a simple automation app that will use Electron JS for good GUI and then Python Selenium to automate the task.

I've just started when I'm trying to run electron JS app it shows that there is no module named as selenium.

Here is my python (demo.py)

    import time
    import re
    from selenium import webdriver
    import webbrowser
    import sys
    from selenium.webdriver.common.keys import Keys
    
    browser = webdriver.Firefox()
    
    browser.get('https://example.com')
    
    userid = browser.find_element_by_id('user')
    time.sleep(1)
    userpass = browser.find_element_by_id('password')
    time.sleep(1)
    userid.send_keys('aafasdf@gmail.com')
    time.sleep(1)
    userpass.send_keys('#jlasdjf#')
    
    
    time.sleep(1)
    userid.send_keys(Keys.RETURN)
    userid.clear()
    browser.refresh()
    time.sleep(5)
    print('Hello from Python!')
    sys.stdout.flush()

And the goes my index.js file
-
function some(){

    var ps = require("python-shell")
    var path = require("path")

    var options = {
        scriptPath : path.join(__dirname,'../seleniumBro/'),
        pythonPath : '/usr/local/bin/python3.8'
    }
 
    ps.PythonShell.run('../../seleniumBro/demo.py', options, function (err, results) {
        if (err) throw err;
        // swal(results[0]);
        console.log(results[0])
      });
    
    

}

在此处输入图像描述

When I run the app I get this error in console.

index.js:12 Uncaught Error: ModuleNotFoundError: No module named 'selenium'
    at PythonShell.parseError (/Users/rahul/Desktop/justDev/electronBro/hello-world/node_modules/python-shell/index.js:258:21)
    at terminateIfNeeded (/Users/rahul/Desktop/justDev/electronBro/hello-world/node_modules/python-shell/index.js:141:32)
    at ChildProcess.<anonymous> (/Users/rahul/Desktop/justDev/electronBro/hello-world/node_modules/python-shell/index.js:133:13)
    at ChildProcess.emit (events.js:223:5)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
    ----- Python Traceback -----
    File "/Users/rahul/Desktop/justDev/seleniumBro/demo.py", line 3, in <module>
      from selenium import webdriver

I'm on MAC OS. And also new to this. Please help.

As per my views. You should go with Node.js as said by pguardio that Selenium is available for node too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM