Skip to main content
  1. About
  2. For Teams
Asked
Viewed 494 times
1

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('[email protected]')
    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])
      });
    
    

}

enter image description here

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.

4
  • 1
    FYI, selenium is available for node too. Otherwise you need to somehow distribute python with your electron app.
    pguardiario
    –  pguardiario
    2020-07-27 00:48:06 +00:00
    Commented Jul 27, 2020 at 0:48
  • @pguardiaro Hey thanks for the information. I've two questions: 1: Instead of Python I should use Node JS? 2: And can I do same automation with Node JS Selenium?
    Agent K
    –  Agent K
    2020-07-27 04:44:11 +00:00
    Commented Jul 27, 2020 at 4:44
  • 1
    It's pretty much the same but more awaits. Another idea is to switch from electron to flask, if you're more comfortable with Python this is probably the way to go.
    pguardiario
    –  pguardiario
    2020-07-28 07:00:10 +00:00
    Commented Jul 28, 2020 at 7:00
  • 1
    Thanks again. I'm new to both electron and Python, and even can learn Node.Js. I hope this should work.
    Agent K
    –  Agent K
    2020-07-29 08:46:52 +00:00
    Commented Jul 29, 2020 at 8:46

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.