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.
Related
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.
I am trying to create a PostgreSQL database with PyQt5.
After creating a database using QSqlDatabase.addDatabase(), calling lastError().text() on that object returns the following:
Driver not loaded Driver not loaded
I have already tried
copying libpq.dll from the PostgreSQL lib folder to Lib\site-packages\PyQt5\Qt\bin in my Python folder
adding sqlite3 to Lib\site-packages\PyQt5\Qt\bin in my Python folder
adding the PostgreSQL lib and include folders to the PATH
This is the code I am using to test:
import sys
from PyQt5.QtSql import *
from PyQt5.QtWidgets import *
app = QApplication(sys.argv)
if not "QPSQL" in QSqlDatabase.drivers():
print('QPSQL not in QSqlDatabase.drivers()')
qQslDb = QSqlDatabase.addDatabase("QPSQL")
qQslDb.setHostName('<Host>')
qQslDb.setDatabaseName('<Name>')
qQslDb.setUserName('<Username>')
ok = qQslDb.open()
if ok:
print("OK, database is open")
else:
print(qQslDb.lastError().text())
exit()
Edit: lastError().text() actually only returns Driver not loaded Driver not loaded. These two lines
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL
come from the call to QSqlDatabase.addDatabase("QPSQL") if I am not mistaken.
For some reason though, when using bash to run the program these two lines are always at the very start of the command line output, even if I put a print("test") in the first line of the program. When using cmd however, it's in the "right" order.
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.
Sorry for pretty stupid question, but I am noob in python.
I got the task to write code that installs and downloads Mozilla Firefox. I code on Mac.
For now I wrote the following:
import os
import urllib
import time
def download():
urllib.urlretrieve('https://download.mozilla.org/?product=firefox-latest&os=win&lang=en-US',
r'/Users/user/Downloads/Firefox 74.0.dmg')
def install():
os.system("cd /Users/user/Downloads/")
time.sleep(15)
os.system("hdiutil mount Firefox\ 74.0.dmg")
time.sleep(15)
os.system("open /Volumes/Firefox/")
time.sleep(15)
def main():
download()
install()
main()
But that's it. I received a lot of pop-up windows and I don't know how to move forward.
Maybe, someone know how execute it?
I can not seem to find any documentation on how to open Opera in incognito mode
Could anyone help me with this please?
this is the part of code i need to include to open opera , but i have no idea how to inlcude the incognito mode
`import os
import webbrowser
os.startfile(C:\\Program Files\\Opera\\launcher.exe)
webbrowser.open`
Use os or subprocess to run the opera luncher with argument --private
somthing like this:
"C:\<path to opera folder>\Opera\launcher.exe" --private
Full code:
import subprocess
command = r'"C:\<path to opera folder>\Opera\launcher.exe" --private'
subprocess.Popen(command)