I am getting the zoom level error for IE which I understand is a known issue. I've been able to find a resolution for this in both Java and C# but I can't seem to find the workaround in Python. Here is what has been reported to work in Java and C#:
System.setProperty("webdriver.ie.driver", IEDriverLocation);
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
aDriver = new InternetExplorerDriver(caps);
Anyone have any experience doing the same thing in Python? I'd also be fine with a set zoom level to 100% but I have not been successful with any iteration of that phrase in python.
You can edit the registry to ensure that the zoom level for IE is set to 100% before launching your test.
The registry setting is at HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Zoom
For 100% zoom, you'll want the value for the ZoomFactor to be 100000 or 186a0 (if you need the hexidecimal value).
Since you're using Python, it looks like you could use the winreg module to edit the Windows registry.
If you are like me, every time you searched for a python specific way to ignore Zoom you found your way here. For anyone else out there who keeps running into this post on Google- you need to pass "ignoreZoomSetting" in as a dictionary when creating a web driver instance. By default, ignoreZoomSetting is set to False:
page = webdriver.Ie(executable_path="C:\\IEDriverServer.exe", capabilities={'ignoreZoomSetting':True})
page.get('https://www.google.com/')
Keep in mind the zoom setting is required for native mouse events, as referenced here. You will probably run into some odd situations as I did.
Related
I like VS2019 and I want to do as much dev on it without needing to switch IDEs constantly. To this, I tried coding in Python but when it came to debugging, it really hold no weight to Pycharm.
For one, the “Autos” variables don’t show on my end:
This is with a project I created within VS2019. Instead to see variables, I have to go to the super cluttered “locals” tab which actually includes for whatever reason, collections, and a bunch of packages cluttering up my debug monitor. I can’t even take out these variables so I can have a cleaner window
In C++, Autos were automatically populated with variables within the scope of the current function call. In the locals everything including stuff I don’t care is there:
The worst part, making classes with multiple values, the object of the class in the debug window can’t even expan to show you the values the object holds like it does so well in Pycharm:
Is there a way to fix this? Different debug monitor windows you can use to make variable tracking as close to and intuitive as Pycharm?
I fixed it by going to Tools->Options->Python->Debugging, and changing it to "use legacy debugger". Unfortunately it doesn't track multipe variables on auto. Just the most recent one
So, as many have encountered Chrome's memory usage can be debilitating so I want to PROGRAMMATICALLY access "Chrome's Task Manager" or something equivalent which displays Tabs, their PIDs, AND SUBFRAMES (if possible) so I can create a script to kill them. After a ton of reading, and a lot of answers suggesting that it might not be possible and some where the posters didn't answer the question, I'm just not sure that the answer to THIS question has truly definitively been given yet.
The closest I've gotten is using "chrome://system/" in the omnibox, but when you expand "mem_usage" it doesn't give you useful memory usage numbers per tab at all and lacks the subframes, but with this method I'd planned to use the tab titles to kill the tabs if I could have actually gotten their memory footprint.
I tried using the win32gui's FindWindowEx method to get the text, but that requires you to know the child element of the text displayed so I downloaded "Window Detective" to see the name of the element(s) the "Chrome Task Manager" displays, the PIDs, and Tab names for, but "Window Detective" only came back with the "EmbeddedMenuWindowClass" which is the entire Window, not related to the text displayed.
I made a fleeting effort to use Selenium, but it seems as though it's just not capable of grabbing Special Menus inside of Chrome over just grabbing tab names and elements within a webpage.
I also tried "pywinauto" but that thing's documentation is really, really bad. I've tried using the "connect" method, "hwndwrapper", etc. but grasping what parameters to use, how their being passed, and what to expect along with how to then use the output you get (such as a list of PIDs or Handles) is seriously bungled. I would have loved if the documentation included the OUTPUT so I could actually see what I'm supposed to get so I don't end up rabbit-holing only to find out that everything I've tested doesn't deliver what I'm looking for. Sorry if that sounds whiny, but I spent hours reading the PDF and the official docs and got badly frustrated.
I also tried launching chrome via the Command Line following this document for logging (http://www.chromium.org/for-testers/enable-logging), but it may be a Chromium only thing, but cannot find the logging document that's created and when I redirect its output to a file, I get nothing useful.
But yes, does anyone know how to programmatically access "Chrome Task Manager's" text, or something else that will deliver similar output? Thank you.
Why to just to use the python os module something like this:
import subprocess as sub
p = sub.Popen(['your command', 'arg1', 'arg2', ...],stdout=sub.PIPE,stderr=sub.PIPE)
output, errors = p.communicate()
print output
You can use the command ps to list all the proceses running in chrome however that only will give you the pid not the name of tab to get that I think the only way is to get the data directly from chorme by creating an extension.
https://developer.chrome.com/extensions/tabs
I am making a simple program that changes the mouse pointer in Windows to a custom .cur image using Python (yes I know you can easily do this via Control Panel but I am using this as a learning tool).
Here is the sample code I used to re-write the registry (will fix wildcard import in final version):
from winreg import *
k = OpenKey(HKEY_CURRENT_USER, 'Control Panel\Cursors',0, KEY_ALL_ACCESS)
SetValueEx(k, 'Arrow',0, REG_SZ, '%SYSTEMROOT%\\Cursors\\rick_serious.cur')
At this point, the registry updates successfully. However, the mouse pointer does not get updated.
After extensive googling, I found this article that explains you need to call a function to "update" the cursor:
link
However, I'm lost as to how to use the SystemParametersInfo function in Python. I came across pypiwin32. However, when I go to the documentation and search for SystemParametersInfo, there is no "SPI_SETCURSORS" action available (as explained in that article).
Is there another way to SPI_SETCURSORS?
If it's possible to do it with this library and I'm not seeing it, could you provide an example as I find this documentation hard to read.
I know the 3 lines of code above don't look like much but several hours of research went into it. Thank you in advance.
I found a way using ctypes. The following line of code updates the cursor which is what you do after setting the registry. The parameters were obtained from Microsoft's website:
import ctypes
ctypes.windll.user32.SystemParametersInfoA(0x0057, 0, None, 0)
I'm kinda new to programming, and I wanna write a simple program that needs to OCR a particular window. Currently, I'm using (w.GetForegroundWindow()), but that gets me the current window which would always be the Python shell, since that is the one that is active when I run it, even if it is for a split second only.
After searching around for a bit, I found the .Getwindows function, but not much of it on Python. What does it do, and what are the parameters? Will i be able to target a particular process (=window) with it? If not, what can I use then?
This is using the pywin32 module on Python 2.7 in Windows
I'm in Windows, Python 2.7 . The GetWindows function comes with the module pywin32, if im not wrong
The usual way is to call EnumWindows with a callback and then get information about each hwnd - for example name, title or window class. Check that against what you are looking for and save the matched hwnd. After EnumWindows returns, check that you found a valid hwnd and use that for your program.
It's not pleasant - there's not much support for this kind of thing in windows. I've heard that using accessibility features is better but I have no experience using that.
I'd like to be able to raise another application's Window using Python.
I did see this, which I suppose I could try:
X11: raise an existing window via command line?
However, I'd prefer to do it in Python if at all possible.
To activate another window, the right thing to do on the Xlib protocol layer is to send a _NET_ACTIVE_WINDOW message as described in the EWMH spec
http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html
This could be done with python-xlib (presumably) or with gdk_window_focus() on a foreign GdkWindow using GDK through pygtk
_NET_ACTIVE_WINDOW is superior to XRaiseWindow() and has been in all the important WMs for many many years.
You should avoid XSetInputFocus() which will cause problems (especially if you get the timestamp wrong). The issue is that the WM can't intercept the SetInputFocus() so it causes weird race conditions and UI inconsistencies.
Really only _NET_ACTIVE_WINDOW works properly, which is why it was invented, because the previous hacks were bad.
There is a library called libwnck that will let you activate windows (among other things) but unfortunately it adds quite a lot of overhead because it always tracks all open windows from any app, even if you don't need to do that. However if you want to track windows from other apps anyway, then libwnck has a function to activate those windows that does the right thing and would be a good choice.
The strictly correct approach is to check for EWMH _NET_ACTIVE_WINDOW support (EWMH documents how to do this) and fall back to XRaiseWindow if the WM doesn't have _NET_ACTIVE_WINDOW. However, since any WM that's been actively worked on in the last many years has EWMH, lots of people are lazy about the fallback for legacy WMs.
You need to use python-xlib and call .circulate(Xlib.X.RaiseLowest) on the window object (which can be identified in many, many different ways -- can't guess which one is appropriate for you from the zero amount of info about it in your Q;-). For a great example of using python-xlib, check out the tinywm window manager -- after the C version, the author gives a Python version that takes about 30 non-blank, non-comment lines (for a usable, if tiny, window manager...!-).
You can have a look at the python ewmh package. Documentation contains examples, but here is how you can achieve what you want:
from ewmh import EWMH
import random
ewmh = EWMH()
# get every displayed windows
wins = ewmh.getClientList()
# let's active one window randomly
ewmh.setActiveWindow(random.choice(wins))
# flush requests - that's actually do the real job
ewmh.display.flush()