How to make Execute JavaScript of RobotFramework return a value
I need the text of a class element be returned using javascript code to a variable within RF. I have tried the following code but I get ${search_result} = None. It's not returning the text within the element selected.
:FOR ${index} IN RANGE 0 23
\ ${search_result} = Execute JavaScript floatMaster.querySelectorAll('#gContact_searcResultshWindow .gContactDetailClientListDiv .gContactListName')[${index}].innerText
I have also tried below but I just get JavascriptException: Message: javascript error: Unexpected number
${search_result} = Execute JavaScript function myFunction(${index}) {return floatMaster.querySelectorAll('#gContact_searcResultshWindow .gContactDetailClientListDiv .gContactListName')[${index}].innerText}()
The reason of the for loop is that the javascript locator has multiple results and I want to make sure each of them carry a specific text. I have a "should contain" command at the end of the loop.
When I try the javascript locator command with the index in browser console, I get a value just fine.
I am also aware of the Execute Async JavaScript command but it seems complicated and I don't understand how it works. Somebody help please.
Try:
${search_result}= Execute JavaScript return floatMaster.querySelectorAll('#gContact_searcResultshWindow .gContactDetailClientListDiv .gContactListName')[${index}].innerText
Omg! It worked. Thank you so much @asprtrmp