Search code examples
pythonlinuxseleniumctypes

LibraryLoader object is not callable typeerror - python cdll - ctypes package


I tried upload scenario with keyboard press simulation through ctypes package in python for selenium webdriver. It is working fine with my local machine installed with windows 8.1.

But when i run the same code in my development server which is a linux box, that will call a remote machine of windows 7 OS, i got error like windll not found in this part of my code

 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)

So I did change my code to a if else statement which prompts if the OS is windows got to above snippet of code else go to below snippet of code,

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)

But after adding this i am getting error in my linux box like

TypeError: 'LibraryLoader' object is not callable.

I did search for resources over internet, but i was not able to get them. Can someone help me to get it through.


Solution

  • I was able to solve the issue with pywinauto package.