0

I have 2 txt file that's have data like that :

Account.txt 
12345
12346
12347

Card.txt
1111
2222
3333

i want to loop both txt file in sametime and input into Text box Card and textbox account .

<form action="">
Account:<br>
<input type="text" name="acc">
<br>
Card:<br>
<input type="text" name="card">
</form>
<button type="submit" form="form1" value="Submit">Bind</button>

I already try to loop but i can only loop one txt file . i can't loop 2 txt file in same time to input textbox . Can anyone give me any suggestion ?enter image description here

4
  • You could store the values in two lists and then use them. Commented Mar 1, 2018 at 7:30
  • Yes , i create 2 list already . Commented Mar 1, 2018 at 10:04
  • If you store the values from the first txt in the first list and the values from the second txt in the second list, you can loop just once and input the account[i] in the first textbox and card[i] in the second textbox Commented Mar 1, 2018 at 10:28
  • Thanks bro let me try use index Commented Mar 1, 2018 at 10:30

2 Answers 2

4

You can use a For-in-zip loop

For example, assuming you read both files and split the data so that you have two arrays @{account} and `@{card}, you can iterate over both lists at the same time like this:

:FOR  ${account}  ${card}  IN ZIP  ${account}  ${card}
\    log  account: ${account} card: ${card}

Here's a complete example:

*** Test Cases ***
Example
    @{account}=    Create List    12345    12346    12347
    @{card}=       Create List    1111     2222      3333

    :FOR  ${account}  ${card}  IN ZIP  ${account}  ${card}
    \    log  account: ${account} card: ${card}
Sign up to request clarification or add additional context in comments.

3 Comments

Could you tell me how to Append file to List by seperate line bro ? INFO [u'23023314\n', u'23026093\n23026094\n'] .
@SidaraKEO that sounds to me like a separate question, which we will happily answer then.
i'm facing with this problems now .
1

Just run an independent FOR-loop und use a variable as index for your arrays:

@{account}    Create List    12345    12346    12347
@{card}       Create List    1111     2222      3333
:FOR         ${iter}         IN RANGE     3 
    Log     Account: @{account}[${iter}]        
    Log     Card: @{card}[${iter}]

Output:

INFO : @{account} = [ 12345 | 12346 | 12347 ]
INFO : @{card} = [ 1111 | 2222 | 3333 ]
INFO : Account: 12345
INFO : Card: 1111
INFO : Account: 12346
INFO : Card: 2222
INFO : Account: 12347
INFO : Card: 3333

1 Comment

Although this is technically possible, you'll have to fetch a count of the list items prior to the loop yourself and the standard functionality :FOR ... IN ZIP ... takes care of this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.