Reputation: 159
I'm trying to get pyautogui's locateOnScreen to work on a virtual machine, so I can run multiple tests at once. I was hoping there's some setting in virtual box that I'm missing that might resolve this. Here's the code:
import pyautogui
import win32com.client
autoit = win32com.client.Dispatch("AutoItX3.Control")
autoit.run(application_path)
open_application = autoit.winWait("title_of_app", "", 10)
header_logo = pyautogui.locateOnScreen("header_logo.png", 10)
if open_application == 1 and header_logo is not None:
print "Detected application window."
else:
if open_application == 0:
print "Failed to detect application window."
assert open_application
else:
print "Failed to detect logo in header of application window."
assert header_logo
Outside of the VM this passes, and inside I always run into "Failed to detect logo in header of application window". I've tried tweaking the image a lot and nothing will take. The main desktop is Windows 7 64-bit and the VM is Window 7 32-bit. Is there a way to get this to work on VirtualBox or any VM software?
Edit: I should add that AutoIt's winWait returns a 1 or 0 and PyAutoGUI's locateOnScreen returns None or the coordinates of where the image was located on screen and the size of the image used.
Upvotes: 3
Views: 3913
Reputation: 159
This is old, but it shows as unanswered. So I figured I'd move my comment where I figured it out, to an answer.
"I was able to solve this issue. The app I'm testing uses quick time to render (or something like that) and for whatever reason this is preventing it from being picked up by pyautogui's screenshot. Using pyqt4, I was able to take a screenshot that contained the app window, convert the Qimage to PIL, and use pyautogui's needle in haystack function (locate function) to find the logo inside the screenshot. I don't know if there's a better way to handle this, but for now it's working."
Upvotes: 1