简体   繁体   English

如何连接 Python Selenium 与 Electron JS App

[英]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.我正在构建一个简单的自动化应用程序,它将使用 Electron JS 获得良好的 GUI,然后使用 Python Selenium 来自动化任务。

I've just started when I'm trying to run electron JS app it shows that there is no module named as selenium.我刚刚开始尝试运行 electron JS 应用程序,它显示没有名为 selenium 的模块。

Here is my python (demo.py)这是我的 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.我在 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.你应该 go 和 Node.js 正如 pguardio 所说,Selenium 也可用于节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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