我尝试通过 python 中的 ctypes 包为 selenium webdriver 上传带有键盘按下模拟的场景。它在我安装了 Windows 8.1 的本地计算机上运行良好。
但是当我在我的开发服务器(一个 Linux 盒子)中运行相同的代码时,它将调用 Windows 7 操作系统的远程计算机,我收到了像 Windll 这样的错误,在我的代码的这一部分中找不到
def SendInput(*inputs):
nInputs = len(inputs)
LPINPUT = INPUT * nInputs
pInputs = LPINPUT(*inputs)
cbSize = ctypes.c_int(ctypes.sizeof(INPUT))
return ctypes.windll.user32.SendInput(nInputs, pInputs, cbSize)
所以我确实将代码更改为 if else 语句,该语句提示操作系统是否是 Windows 转到上面的代码片段,否则转到下面的代码片段,
cdll.LoadLibrary("libc.so.6")
Xtst = cdll("libXtst.so.6")
Xlib = cdll("libX11.so.6")
dpy = Xtst.XOpenDisplay(None)
def SendInput(txt):
for c in txt:
sym = Xlib.XStringToKeysym(c)
code = Xlib.XKeysymToKeycode(dpy, sym)
Xtst.XTestFakeKeyEvent(dpy, code, True, 0)
Xtst.XTestFakeKeyEvent(dpy, code, False, 0)
Xlib.XFlush(dpy)
但是添加此后,我的 linux 盒子中出现错误,例如
TypeError: 'LibraryLoader' object is not callable.
我确实通过互联网搜索资源,但无法找到它们。有人可以帮我解决这个问题吗?
我能够使用 pywinauto 包解决问题。