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.
Related
When I run my selenium python tests via right click run in PyCharm, all is good. However, when I try to run with command line (pytest), I get error. Here is my folder structure:
[projectname]/
├── Driver
├── Driver.py
├── Tests
├── TestFolder
├── TestName.py
Driver.py file looks like this:
from selenium import webdriver
Instance = None
def Initialize():
global Instance
Instance = webdriver.Chrome()
Instance.implicitly_wait(2)
return Instance
def QuitDriver():
global Instance
Instance.quit()
TestName.py looks like this:
import unittest
from Driver import Driver
from Tests.Transactions.HelperFunctions import *
class StreamsTest(unittest.TestCase):
#classmethod
def setUp(cls):
Driver.Initialize()
def testSameDayEverySecond(self):
ConnectSenderWallet()
AppPage.HandleDevAmountsTitleAndAddress()
HandleCreateAndAssert()
#classmethod
def tearDown(cls):
Driver.QuitDriver()
And when I run pytest -v -s Tests/TestFolder/TestName.py, I get following errors in my console:
ImportError while importing test module '/Users/dusandev/Desktop/w-test/Tests/TestFolder/TestName.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../miniconda3/lib/python3.9/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
Tests/TestFolder/TestName.py:2: in <module>
from Driver import Driver
E ModuleNotFoundError: No module named 'Driver'
Thank you for your help!
Python is trying to load the Driver class from Driver.py, however, you don't have one. You may want to do one of the following:
Create a Driver class in Driver.py
Replace from Driver import Driver with from Driver import *
Replace from Driver import Driver with import Driver
I am working with Anaconda-spyder, my scripts are working fine in spyder also I can run it from CMD
but I can not run my scripts with my Nodejs app
Nodejs
const express = require('express');
const router = express.Router();
const {PythonShell} = require("python-shell");
router.get('/hi', (req, res, next)=> {
console.log("here");
PythonShell.run('pyt//home.py', {
args: ['infoo']
}, function (err, results) {
console.log("here2");
if(results)
{ console.log(results);}
if(err)
{ console.log(err);}
});
});
module.exports = router;
In python code, used libraries
import os
import sys
import tweepy,codecs
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import nltk
from textblob import Word
import six
import numpy as np
import pandas as pd
from os import path
from PIL import Image
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
from nltk.corpus import stopwords
from matplotlib.backends.backend_pdf import PdfPages
import time
And getting the argv parameter in home.py with
if __name__ == "__main__":
twt = sys.argv[1]
print("hi python")
When I run server, get the route with postman. console says
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node ./bin/www`
here
here2
{ Error: ModuleNotFoundError: No module named 'pandas'
at PythonShell.parseError (C:\Users\username\Desktop\NodejsBitirme\node_modules\python-shell\index.js:258:21)
at terminateIfNeeded (C:\Users\username\Desktop\NodejsBitirme\node_modules\python-shell\index.js:141:32)
at ChildProcess.<anonymous> (C:\Users\username\Desktop\NodejsBitirme\node_modules\python-shell\index.js:133:13)
at ChildProcess.emit (events.js:198:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
----- Python Traceback -----
File "pyt\home.py", line 9, in <module>
Seems like installed libs problem. It work from cmd.
In the same folder
python home.py "hello"
It works
I am using python 2.7 but am not able to get anything how to read url which are active in tab of browsers.
So far i tried this
import win32gui
import win32process
import psutil
#w=win32gui
#value=w.GetWindowText(w.GetForegroundWindow())
#print(value)
appwindow = win32gui.GetForegroundWindow()
ProcessID = win32process.GetWindowThreadProcessId(appwindow)
#procname = psutil.Process(ProcessID)
#applicname = procname.name()
print("hello")
Check out pybrinf package, is Windows supported and allows you to get some info about a browser.
Using this code to for capturing image and it is running well on spyder-anaconda but I want to integrate with my app which is made on node.js platform but unable to do so.
the beginning of python code is as follows :
//cam_open.py
import cv2
import numpy as np
aarcascade_frontalface_default.xml"
detector=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cam = cv2.VideoCapture(0)
#------Id=raw_input('enter your id')----
Id=1
path= 'Dataset1'
sampleNum=0
while(True):
ret, img = cam.read();
.
.
.
and code for integrating with node.js is as follows:
(note: I have used this code to run other python scripts and it is running perfect on them but when I include opencv it is giving me errors even though I have added opencv path to my environment variables too)
//index.js
var PythonShell = require('python-shell');
var pyshell = new PythonShell('cam_open.py');
pyshell.on('message', function (message) {
console.log(message);
});
the error I'm getting is as follows:
HIBA#hiba-pc MINGW64 ~/documents/sabah/driver-comp/test
$ node index.js
events.js:137
throw er; // Unhandled 'error' event
^
Error: ImportError: No module named cv2
at PythonShell.parseError (C:\Users\HIBA\documents\sabah\driver-comp\node_modules\p
ython-shell\index.js:184:17)
at terminateIfNeeded (C:\Users\HIBA\documents\sabah\driver-comp\node_modules\python
-shell\index.js:98:28)
at ChildProcess.<anonymous> (C:\Users\HIBA\documents\sabah\driver-comp\node_modules
\python-shell\index.js:89:9)
at ChildProcess.emit (events.js:160:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
----- Python Traceback -----
File "cam_open.py", line 1, in <module>
import cv2
Can anybody here help me get out of this :)
I am trying to integrate LDTP and selenium in python environment for automation upload an image to "http://imgure.com/"
My environment as below:
OS: Ubuntu 15.10
Python: v3.5/v2.7
IDE: Pycram 2016.1
LDTP: v3.5
from selenium import webdriver
import ldtp
def main():
browser = webdriver.Firefox()
browser.implicitly_wait(5000)
browser.get("http://imgur.com/")
browser.maximize_window()
browser.find_element_by_css_selector("li.upload-button-container").click()
browser.find_element_by_css_selector("div#upload-global-file-wrapper").click()
ldtp.maximizewindow("File Upload")
#Call LDTP's mouserightclick function
ldtp.mouseleftclick('File Upload', 'btnOpen')
browser.find_element_by_css_selector("button#upload-global-start-button.button-big.green").click()
if __name__ == '__main__':
main()
My Pycram screenshot:
Pycram screenshot
Pycram can't find mouseleftclick function when i try to use mouseleftclick.
Does anyone know how to fix this issue? Thanks.