Sikuli automation to pull data from csv and enter in browser app

Asked by DJ

I am trying to automate application data entry into a application on firefox web browser using sikuli. I am pulling data from a csv and entering that data into a application gui on firefox web browser. My current sukili script is built but when I run it nothing happens it does not switch to the web browser and start the data entry from the csv. Any help would be appreciated. I'm missing something but I am not seeing it.
Below is my sikuli script

import csv
import sys

########################################################################################################################
# Config
########################################################################################################################

SFTPProfileCSV = 'C:/Users/w299833/Downloads/FGinfoforSikuli.csv'

# browser='Windows Internet Explorer'
browser = 'Mozilla Firefox'

#What order the protocol is in, in the custom protocol list
orderOfCustomProtocol=11
timeBetweenScreens = 5 # How many seconds till the next screen draws

### Screen you should be on is Participants>Partners and cursor should be in the search box, then you can run sikuli script #####

########################################################################################################################
# Basic / Keyboard functions
########################################################################################################################
def type_up(n):
    while(n > 0):
        type(Key.UP)
        n = n - 1

def type_down(n):
    while(n > 0):
        type(Key.DOWN)
        n = n - 1

def type_tab(n):
    while(n > 0):
        type(Key.TAB)
        n = n - 1

def type_shift_tab(n):
    while(n > 0):
        type(Key.TAB, KEY_SHIFT)
        n = n - 1

########################################################################################################################
# SIKULI SCREEN AUTOMATION
########################################################################################################################
def sfg_update_profile(Producer, Clientname, BU, Owneremail, Password):
    switchApp(browser)

    #Get from the landing page on "Partners" screen to the "Edit Partner" screen

    #We are required to have the partner filter box selected and empty
    type_tab(3)
    type(Key.ENTER)
    sleep(timeBetweenScreens)

    #Add Partner
    type_tab(1)
    type(Key.DOWN)
    type_tab(1)
    type(Key.ENTER)
    sleep(timeBetweenScreens)

    #Add Partner Information
    type_tab(1)
    paste(Producer)
    type_tab(1)
    paste(Producer)
    type_tab(1)
    paste(Clientname)
    type_tab(2)
    paste(BU)
    type_tab(3)
    paste(NA)
    type_tab(3)
    paste(Owneremail)
    type_tab(2)
    type(Key.ENTER)
    sleep(timeBetweenScreens)

    #Add Partner User Account
    type_tab(2)
    paste(Producer)
    type_tab(1)
    paste(Password)
    type_tab(1)
    paste(Password)
    type_tab(1)
    type(Key.DOWN)
    type_tab(2)
    paste(Producer)
    type_tab(1)
    paste(Producer)
    type_tab(2)
    type(Key.ENTER)
    sleep(timeBetweenScreens)

    #Add Partner Partner Role
    type_tab(1)
    type(Key.Space)
    type_tab(1)
    type(Key.Space)
    type_tab(2)
    type(Key.ENTER)

    #Finish Screens no changes
    type_tab(3)
    type(Key.ENTER)
    type_tab(2)
    type(Key.ENTER)
    type_tab(3)
    type(Key.ENTER)

    #Close the edit community tab
    type("w", Key.CTRL)
    sleep(timeBetweenScreens)

    #Get back to where we can paste the next partner
    type_shift_tab(4)

########################################################################################################################
# MAIN
########################################################################################################################

def main():
    RowStart = int(input("What row number in the FTP file \nshould I START with?"))
    RowEnd = int(input("What row number in the FTP file \nshould I END with?"))
    RowStart = RowStart -1 #CSVs are zero initialized but we're skipping the title row

        # Open file for reading, as a text file = rU
    # csvFileGuy = (open(SFTPProfileCSV, 'rU'))

    profiles = []
    with open(SFTPProfileCSV, 'rU') as csvFileGuy:
        reader = csv.reader(csvFileGuy)
        for row in reader:
            profiles.append(row)
            # print(row)

    for n in range(RowStart, RowEnd):
        Producer = str(profiles[n][0]).strip()
        Clientname = str(profiles[n][2]).strip()
        BU = str(profiles[n][3]).strip()
        Owneremail = str(profiles[n][4]).strip()
        Password = str(profiles[n][5]).strip()

if __name__ == "__main__":
    main()

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Roman Podolyan (podolyan-roman) said :
#1

1) When I needed switching to some app, I did it using taskbar clicking, not switchApp. I took some image (like Firefox icon) from launched taskbar application, and told Sikuli to click it.
2) Depending on which OS you using, you may need to do a click once or even twice on a window you do bring to front.

Also it looks you like don't want to use any visual recognition things, just typing, switching by pressing, tab entering text etc. In this case you probably might be better off investing some time in learning Selenium and using Selenium functions, not Sikuli

Revision history for this message
masuo (masuo-ohara) said :
#2

switchApp(browser) is called in function "sfg_update_profile".
But function "sfg_update_profile" is not called from anywhere.

Revision history for this message
Roman Podolyan (podolyan-roman) said :
#3

Tell me please what you _expect_ to happen when you run this code, and what _happens_ .
Yes, you don't call "sfg_update_profile" — but what you expect to happen when code runs, then?

Revision history for this message
DJ (wasko-dj) said :
#4

Basically the sikuli script should go through the csv and take the data that I designate and add it into my application gui via browser. Basically it is running through the process to create an ID.
I have the sfg_update_profile data in the code now
import csv
import sys

########################################################################################################################
# Config
########################################################################################################################

SFTPProfileCSV = 'C:/Users/w299833/Downloads/FGinfoforSikuli.csv'

# browser='Windows Internet Explorer'
browser = 'Mozilla Firefox'

#What order the protocol is in, in the custom protocol list
orderOfCustomProtocol=11
timeBetweenScreens = 5 # How many seconds till the next screen draws

### Screen you should be on is Participants>Partners and cursor should be in the search box, then you can run sikuli script #####

########################################################################################################################
# Basic / Keyboard functions
########################################################################################################################
def type_up(n):
    while(n > 0):
        type(Key.UP)
        n = n - 1

def type_down(n):
    while(n > 0):
        type(Key.DOWN)
        n = n - 1

def type_tab(n):
    while(n > 0):
        type(Key.TAB)
        n = n - 1

def type_shift_tab(n):
    while(n > 0):
        type(Key.TAB, KEY_SHIFT)
        n = n - 1

########################################################################################################################
# SIKULI SCREEN AUTOMATION
########################################################################################################################
def sfg_update_profile(Producer, Clientname, BU, Owneremail, Password):
    switchApp(browser)

    #Get from the landing page on "Partners" screen to the "Edit Partner" screen

    #We are required to have the partner filter box selected and empty
    type_tab(3)
    type(Key.ENTER)
    sleep(timeBetweenScreens)

    #Add Partner
    type_tab(1)
    type(Key.DOWN)
    type_tab(1)
    type(Key.ENTER)
    sleep(timeBetweenScreens)

    #Add Partner Information
    type_tab(1)
    paste(Producer)
    type_tab(1)
    paste(Producer)
    type_tab(1)
    paste(Clientname)
    type_tab(2)
    paste(BU)
    type_tab(3)
    paste(NA)
    type_tab(3)
    paste(Owneremail)
    type_tab(2)
    type(Key.ENTER)
    sleep(timeBetweenScreens)

    #Add Partner User Account
    type_tab(2)
    paste(Producer)
    type_tab(1)
    paste(Password)
    type_tab(1)
    paste(Password)
    type_tab(1)
    type(Key.DOWN)
    type_tab(2)
    paste(Producer)
    type_tab(1)
    paste(Producer)
    type_tab(2)
    type(Key.ENTER)
    sleep(timeBetweenScreens)

    #Add Partner Partner Role
    type_tab(1)
    type(Key.Space)
    type_tab(1)
    type(Key.Space)
    type_tab(2)
    type(Key.ENTER)

    #Finish Screens no changes
    type_tab(3)
    type(Key.ENTER)
    type_tab(2)
    type(Key.ENTER)
    type_tab(3)
    type(Key.ENTER)

    #Close the edit community tab
    type("w", Key.CTRL)
    sleep(timeBetweenScreens)

    #Get back to where we can paste the next partner
    type_shift_tab(4)

########################################################################################################################
# MAIN
########################################################################################################################

def main():
    RowStart = int(input("What row number in the FTP file \nshould I START with?"))
    RowEnd = int(input("What row number in the FTP file \nshould I END with?"))
    RowStart = RowStart -1 #CSVs are zero initialized but we're skipping the title row

        # Open file for reading, as a text file = rU
    # csvFileGuy = (open(SFTPProfileCSV, 'rU'))

    profiles = []
    with open(SFTPProfileCSV, 'rU') as csvFileGuy:
        reader = csv.reader(csvFileGuy)
        for row in reader:
            profiles.append(row)
            # print(row)

    for n in range(RowStart, RowEnd):
        Producer = str(profiles[n][0]).strip()
        Clientname = str(profiles[n][2]).strip()
        BU = str(profiles[n][3]).strip()
        Owneremail = str(profiles[n][4]).strip()
        Password = str(profiles[n][5]).strip()

        print("Consumer = " + Consumer + ", Owneremail = " + Owneremail + ", Password = " + Password + ", PreProcess = " + PreProcess + ", Profile = " + Profile + ", RepType = " + RepType + ", Completionemail = " + Completionemail + ", Erroremail = " + Erroremail + ", Commonname = " + Commonname + ")
        sfg_update_profile(Consumer, Owneremail, Password, PreProcess, Profile, RepType, Completionemail, Erroremail, Commonname)

if __name__ == "__main__":
    main()

Revision history for this message
Roman Podolyan (podolyan-roman) said :
#5

And what happens now? :)
Do you see dialogs you coded with input() function?
What page is opened in browser before scripts starts?
Do you see any action on browser? Do you see in console data printed by print function?

It is a debug process, you know. One starts small and looks programs work, step by step, with debug statements in code and/or observing actions, telling if one gets after step N what one expects after it.

Revision history for this message
DJ (wasko-dj) said :
#6

I currently get this error message
[error] script [ CreateProducer ] stopped with error in line 150 at column 4
[error] SyntaxError ( "no viable alternative at input 'if'", )

Revision history for this message
DJ (wasko-dj) said :
#7

I wrote these about 8 months ago and have not used them or worked on them since. I recently got back into them and I am trying to figure them out.
I have some that I wrote 8 months ago that work correctly but I am trying to stream line the csv file column length. I am also building some new ones like this one using the templates I used 8 months ago.

Revision history for this message
Roman Podolyan (podolyan-roman) said :
#8

> [error] script [ CreateProducer ] stopped with error in line 150 at column 4
> [error] SyntaxError ( "no viable alternative at input 'if'", )

That means that you got a problem with mixing tabs and spaces or some inconsistent indents. Open with some editor allowing you to see Python indents and/or invisible chars and check them everywhere.

Also this like must be fixed:
 print("Consumer = " + Consumer + ", Owneremail = " + Owneremail + ", Password = " + Password + ", PreProcess = " + PreProcess + ", Profile = " + Profile + ", RepType = " + RepType + ", Completionemail = " + Completionemail + ", Erroremail = " + Erroremail + ", Commonname = " + Commonname + ")

That + ") in the end is not correct.

Can you help with this problem?

Provide an answer of your own, or ask DJ for more information if necessary.

To post a message you must log in.