Reputation: 10439
I have some web elements which has the same prefix for their ID
attribute. I can get these elements all at once with get webelements
; I want to extract their text attribute with one command. I have wrote this line:
${elList} = get webelements xpath=//*[starts-with(@id, '${formName}:${row}')]
${rowList} = evaluate [item.get_attribute('text') for item in ${elList}] selenium
Which returns:
Evaluating expression '[item.get_attribute('text') for item in [<selenium.webdriver.remote.webelement.WebElement object at 0x7f7b6c5f09d0>, <selenium.webdriver.remote.webelement.WebElement object at 0x7f7b6c5f0990>]]' failed: SyntaxError: invalid syntax (<string>, line 1)
I can't understand the problem here; BTW I'll appreciate any other solution for my issue.
EDIT1: I also have tried below code:
${elList} = get webelements xpath=//*[starts-with(@id, '${formName}:${row}')]
:FOR ${item} IN @{elList}
\ log to console ${item.get_attribute('text')}
But the console just shows None
; it is the same for ${item.get_attribute('value')}
.
Upvotes: 2
Views: 15656
Reputation: 1442
you could use this also.
@{elem} = Get WebElements css=._1vC4OE._2rQ-NK
:FOR ${item} IN @{elem}
\ log to console Item: ${item.text}
Upvotes: 3
Reputation: 10439
I've solved this; I found this answer and used ${item.get_attribute('innerHTML')}
as a try. It worked pretty fine.
Upvotes: 3
Reputation: 5902
Is text
an actual attribute or just the containing text? If it is an attribute then perhaps you can try the following method.
${count}= Get Matching Xpath Count //*[starts-with(@id, '${formName}:${row}')]
${rowList}= Create List
:FOR ${i} IN RANGE ${count}+1
\ ${text}= Get Element Attribute xpath=(//*[starts-with(@id, '${formName}:${row}')])[${i}]@text
\ Append To List ${rowList} ${text}
Upvotes: 1