Richard Hoang
Richard Hoang

Reputation: 11

Add string value to list

My web AUT has about 17 line of text in a table. I have already get each value to a temp variable. And now I want to add that string to the list.

I am getting the following error:

AttributeError: 'str' object has no attribute 'insert'

For example, I have the following text line:

Text Line 1
Text Line 2
Text Line 3
...

And I want to add them to the list like this:

@{mylist} = Text Line 1 | Text Line 2 | Text Line 3

Here is my code, in Robot Framework format:

@{list} Create List ${EMPTY}            
${list position}    Set Variable    0           
${number of row}    Get Matching Xpath Count    //table[@class="GridView"]//tr          
${i}    Set Variable    2           
: FOR   ${i}    IN RANGE    2   ${number of row}    
    ${i}    Convert To String   ${i}        
    ${item control} Replace String  ${table profile name default value} rownumber   ${i}
    ${item name}    Get Text    ${item control}     
    Append To List  @{list} ${item name}        

Upvotes: 0

Views: 12349

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386020

This is the problem line:

Append To List  @{list}  ${item name} 

The problem is the use of @. You need to use $:

Append To List  ${list}  ${item name} 

(you also seem to have the problem that you only have a single space between the last two arguments)

Using $ refers to the list as an object; using @ expands the list as if you had typed them into individual cells in the test.

Upvotes: 6

Related Questions