1

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.

javascript locator result from browser console

When I try the javascript locator command with the index in browser console, I get a value just fine. enter image description here

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.

1 Answer 1

1

Try:

${search_result}=    Execute JavaScript    return floatMaster.querySelectorAll('#gContact_searcResultshWindow .gContactDetailClientListDiv .gContactListName')[${index}].innerText
Sign up to request clarification or add additional context in comments.

Comments

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.