← Back to team overview

sikuli-driver team mailing list archive

[Question #234579]: How to increment or combine Sikuli variables?

 

New question #234579 on Sikuli:
https://answers.launchpad.net/sikuli/+question/234579

My script needs to log in to several accounts, each in a separate browser tab.
I already took care of opening the browser, opening multiple tabs, and starting the web app in each tab.
Now, I would like to use pre-defined account/password pairs, and increment their "counter" for each step in the loop.

Currently, my code looks like this:

# Define account variables
acct1 = "Andrew"
acct2 = "Bill"
acct3 = "Chris"
[skip a bunch of lines]
acct22 = "Richard"

pass1 = "andyspass"
pass2 ="billyspass"
pass3 ="chrispass"
[skip a bunch of lines]
pass22 = "rickspass"

# LOGIN ACCT 1
type(account1 + Key.TAB + pass1), click("Login.png") <---- This WORKS
wait(10)
type(Key.TAB, KeyModifier.CTRL) # Switch to next tab
# END ACCT1 LOGIN

# LOGIN ACCT 2
type(account2 + Key.TAB + pass2), click("Login.png") <---- This WORKS
wait(10)
type(Key.TAB, KeyModifier.CTRL) # Switch to next tab
# END ACCT2 LOGIN

And so on, and so on - 22 times!

I know you can increment 1 variable, such as:

x = 0       # start value
x += 1    # increments x
type(x)  # prints "1"

However, when I try to combine the static "acct" + auto-increment, the syntax fails:

----------------------------------------------------------------------------------

x = 0      # start value
for a in range (22):
    x += 1 # increment x
   type("account"+str(x) + Key.TAB + "pass"+str(x)) <---- THIS DOESN'T WORK !!!
   click("Login.png")
   wait(10)
   type(Key.TAB, KeyModifier.CTRL) # Switch to next tab

---------------------------------------------------------------------------------

So, how can I increment 1 variable ("x"), add it to a string, and pass the *combined* "stringx" as an argument to the type() function?

In other words, I want Sikuli to auto-generate "acct1", "pass1", "acct2", "pass2", and so on, until "acct22", "pass22".

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.