On SikulixIDE, the library webbrowser always open the default browser, even when i use the get method, i tried my code on regular python, it does work. Anyone know why it is reacting like that ?
webbrowser.get('C:/Program Files/Google/Chrome/Application/chrome.exe %s').open(myurl)
Fixed by automating it using a python file and running it trough cmd with base python.exe.
Related
I'm trying to simulate "double click" or enter on a selected file in windows explorer (win10pro) after I've run this code:
import subprocess
os.chdir("C:/Users/***/***/DeforumStableDiffusionLocal")
subprocess.Popen(r'explorer /select, "C:\Users\***\***\DeforumStableDiffusionLocal\run_still.bat')
I've tried importing the keyboard module but I'm a little confused as to how it would interact with the opened explorer window.
Normally i would run within python, but I'm trying to streamline with another program where I'm getting weird SSL errors from within the program, but when run in windows explorer it works fine. Thanks in advance!
In native Windows you would use ShellExecute. In Python you should use os.startfile(myfilepath).
I'm running a couple of things on my home server, two of which are Minecraft servers. I want to set up an automatic restart of the computer every week, but first want to close the servers in the correct way. This is done by sending the command "stop" in their specific CMD windows.
I've successfully been able to select and open specific CMD windows as shown below:
import pygetwindow as gw
handle = gw.getWindowsWithTitle('C:\Windows\system32\cmd.exe')[0]
handle.activate()
My problem is that I can't seem to be able to send the "stop" command in those specific windows. If I for example run the following commands instead:
import pygetwindow as gw
import os
print(gw.getAllTitles())
handle = gw.getWindowsWithTitle('C:\Windows\system32\cmd.exe')[0]
handle.activate()
os.system("stop")
It doesn't do anything because it opens a new CMD window. There might be other issues as well, but since I haven't been able to solve that issue I haven't encountered them yet.
I would really appreciate some help, cause I'm stuck.
I would use a plugin like AutoRestart https://www.spigotmc.org/resources/autorestart.2538/ for Spigot. If you're on vanilla, I would reccomend upgrading to Spigot (or i like to use Pufferfish/Paper)
I'm currently using SublimeText3 and R for my data analysis work. I simply open an R-REPL in Sublime Text and press CNTRL+Enter from a written script to evaluate a line of code. I would like to do this same process with Python, but when I try to send the Python script to the open Python REPL using CTRL+Enter, I receive the error "Cannot find REPL for R."
I believe this has something to do with my default path for the REPL in my user settings,
"default_extend_env": {"PATH": "{PATH};\\Program Files\\R\\R-3.1.0\\bin\\x64"}
However, I don't know how to generalize this to work with multiple environments. It would be very convenient for me to have Python and R scripts open and be able to send commands to their respective windows.
How do I fix this?
While running Selenium tests on a website, I have some Flash elements that I cannot test with Selenium/Python. I wanted to call out for a separate terminal window, run the Sikuli OCR tests, and then back into the Selenium/Python testing. I've not been able to figure this out exactly. I put XXX where I do not know the arguments for a new Terminal to open and run the Sikuli script.
def test_05(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_link_text("Home").click()
driver.find_element_by_id("open_popup").click()
driver.find_element_by_id("screen_name").send_keys("user")
driver.find_element_by_id("password").send_keys("pwd")
driver.find_element_by_id("login_submit").click()
driver.find_element_by_id("button").click()
time.sleep(120)
os.system('XXX')
os.system('./Sikuli/sikuli-script -r test.sikuli')
I am sure there are a couple items wrong here. Any help would be greatly appreciated. I've searched and read what I can find on this already, but can't get it all to work together.
I ran into a similar issue, so I wrote a CPython module for Sikuli. The module is hosted on GitHub and available via pip install sikuli. It's able to access an included Sikuli jar using pyjnius, so you don't have to use Jython or even install Sikuli itself (although I'd recommend it for recording purposes). The module currently covers most of the simpler Sikuli functions, so it should cover a lot of use cases.
After installing, a simple from sikuli import * will get you started, but as a best practice, I'd suggest only importing the functions you want to use. This is particularly important for this module, because sikuli has a type function which overrides Python's own type function.
If your sikuli script is completely independent and you just want to run it for once and then have control back to your python script.
Then you can create a batch file, which calls your sikuli script and call this batch file from your python script instead.
Once the batch file is done running, it exits and returns the control back to your python script.
Sample Batch file:
#echo off
call C:\Sikuli\runIDE.cmd -r C:\Automation\Test1.sikuli
exit
Code snippet to call Sikuli script from inside python:
import subprocess
def runSikuliScript(path):
filepath = path
p = subprocess.Popen(filepath, shell=True, stdout = subprocess.PIPE)
stdout, stderr = p.communicate()
print "Done Running Sikuli"
p = "C:\\Automation\\Test1\\test1.bat"
runSikuliScript(p)
// You can carry on writing your python code from here on
For calling Sikuli code from Selenium, my first choice would be TestAutomationEngr's suggestion of using Java, since Selenium and Sikuli both have native Java bindings.
Since you want to use Python, you should try running Selenium under Jython. It's important to remember that Sikuli is Jython, which is probably why you're not able to import it. (The other reason would be that you don't have it in Jython's module path.) I have not tried this myself, but there was a bug fixed last year in Selenium which indicates that it should be fine under Jython.
Note that if you call your Sikuli code directly from Jython, you need to add
from sikuli.Sikuli import *
to the top. This is because the Sikuli IDE implicitly adds that to all Sikuli code.
Finally, your last resort is to call Sikuli from the command line. There's an FAQ for that. You probably want the "without IDE" version, where you're calling Java and passing in the sikuli-script JAR file.
>>> webbrowser.open("www.python.org")
False
Is there any other way to get the same functionality of that function in Cygwin?
export BROWSER=cygstart
before starting Python. Then it should work.
Launching a web browser from Cygwin can be done through
cygstart "http://www.google.com"
where google.com is your desired URL.
cygstart launches the default windows program for a path, so this way you get the user’s preferred web browser.
So in Python under Cygwin you might just:
from subprocess import call
call(["cygstart", "http://www.google.com"])
or try another option from here to run the Python-external command.
If it's not just a one-off script you are writing for your own use, you should use platform.system to use the above on Cygwin, and webbrowser.open on other platforms.