Qlik Community

Qlik Sense Documents & Videos

Documents & videos about Qlik Sense.

Announcements
See why Qlik is recognized as a Leader for the 10th year in a row – and discover how Qlik can help put your business in the lead. Get Report

QlikSense Desktop Automation with Python

Partner
Partner

QlikSense Desktop Automation with Python

Hello passionate  Python and Qsense people.

In a post of november last year, I explained on how to automate a qlikview process with python using  a class  I’ve made for this purpose. 

Now is time to see if we can play with some qliksense desktop automation. What i’m going to show is really basic: from python we will be able to start QlikSense and proceed with log in.  

Before to begin, we need to have qliksense desktop already installed , defined username and password, log in  at least one time having the remember password flag set.

We are going to use two main library, subprocess to start qliksense and pywinauto to automate the button to press for login.

Looking at the code, Subprocess.Popen start qliksense process and send info to standard output using a pipe. this because  Qliksense when start, return a list of node process  with PID number.

Next, we can see a while loop parsing lines returned by qliksense until it found the one representing the main process window.

So at the end the PID is defined, pywinauto  is connected trough the PID to the qliksense process to find the Qliksense desktop window, once found it, put the window on focus  and after the dialog search for the LOG IN BUTTON, if found, will press on it. You may have to adjust the connection timeout increasing or decreasing the value according your installation. Also you may have to change the app_dialog["LOG IN"] according your locale language, for example Italians will put  app_dialog["ACCEDI"]

A last note: the  print(app_dialog.print_control_identifiers()) will show you all the control  related to the qsense window so it will be possible to enter username and password programmatically.

Here the source code used with python 3.7, pywinauto 0.6.8, QlikSense November 2019 :

from pywinauto import application

import subprocess

 

proc = subprocess.Popen(r"C:\\Users\\MYUSER\\AppData\\Local\\Programs\\Qlik\\Sense\\QlikSense.exe",

                        cwd="C:\\Users\\MYUSER\\AppData\\Local\\Programs\\Qlik\\Sense", stdout=subprocess.PIPE,)

 

print('*******************************************************************')

 

k = 0

while True:

        line = proc.stdout.readline().rstrip().decode('ASCII')

        print(line)

        if k > 0 and k < 3:

            k = k + 1

        if k == 3:

            browser_line = proc.stdout.readline().rstrip().decode('ASCII')

            print(browser_line)

            k = 0

            break

        if line == "ExePath = PrintingService\Printing.exe":

            print(found command')

            k = k + 1

        if line == 'Script = AboutService\index.js':

            break

        if not line:

            break

 

split_process = browser_line[browser_line.find('process'):]

split_process = split_process[9:]

pid = split_process[:split_process.find(')')]

print(pid)

pid = int(pid)

app = application.Application(backend='uia').connect(process=pid, timeout=5)

print(app)

app_dialog = app.window(title_re="Qlik Sense Desktop")

if app_dialog.exists():

    app_dialog.set_focus()

    print("QSENSE WINDOW FOUND")

print(app_dialog.print_control_identifiers())

access = app_dialog["LOG IN"]

access.click()

 

 

Version history
Revision #:
1 of 1
Last update:
4 weeks ago
Updated by:
 
Contributors