How to specify a "Arguments" with a space in Robot Framework keyword?

15,741

Solution 1

Like the other answer said - single spaces are not escaped. The space is read from your script.

If however, you need to make sure, you can always use the built in value

${SPACE}

For example:

Sign${SPACE}In

Solution 2

The literal answer to your question "How to specify a “Arguments” with a space in Robot Framework keyword?" is that you don't have to do anything special. If the argument has a space it will work just fine. if the argument has multiple spaces and you're using the space-separated format, you'll need to escape the spaces. That's not the situation with the code you posted, however.

The problem isn't a space, the problem appears to be that there isn't an element on the page that matches the locator "sign in". The element has an id of "signIn" and a value of "Sign in", but nothing matches "sign in". Case is apparently important. If you change your code to use the proper case, the test should work:

Click Button    Sign in

Note: it's generally preferable to use ids as locators when they are available. In your case it would be:

Click Button    id=signIn

Solution 3

by using ${SPACE} keyword to we can resolve the issue. If you use the ${SPACE} keyword, Robot will understand it so that you would have one keyword ${msg}= HELLO${SPACE*5}WORLD Log ${msg}

Output: HELLO WORLD

Share:
15,741

Related videos on Youtube

Kumar
Author by

Kumar

Updated on September 15, 2022

Comments

  • Kumar
    Kumar over 1 year

    I am trying to automate the "gmail" login process.

    I have written following keywords. When I run this, first two keywords are running successfully. "Click Signin Button" keyword throws "invalid locator or ID : sign in" error. Taken this "sign in" from Inspect Element in "chrome" browser.

    *** Keywords ***
    Go to gmail page
        Open Browser    ${HOMEPAGE}     ${BROWSER}
    
    Login Page Should Be Open
        Location Should Be      ${LOGINPAGE}    
    
    Click Signin Button
        Click Button        sign in
    

    Could anyone please tell, how to give this "sign in" locator (contains a space).

    Thanks,

    Kumar

  • Kumar
    Kumar over 9 years
    Thanks for you answer. Still I am seeing same issue. I tried by specifying "Sign in" {Sign in} 'Sign in' etc. Is there any other way to specify this? I have automated the same process using firefox browser. In firefox there is no space issue.
  • Russell Smith
    Russell Smith over 9 years
    @Kumar: I took your keyword and it ran just fine for me using Chrome when I specified the locator with a capital "S". Are you certain you're typing it with a capital "S"? Also, don't add your own quotes. Do it exactly like in my answer. Again, I don't think the problem is related to the space. Robot will send the string exactly as you type it -- it doesn't add or remove any extra spaces.
  • Russell Smith
    Russell Smith over 9 years
    Actually, what I wrote isn't precisely true, as robot strips off leading and trailing spaces, but that's not relevant to this question.
  • Kumar
    Kumar over 9 years
    I am not getting the meaning of ${SPACE}. Do you mean "Sign${SPACE}in"?
  • Russell Smith
    Russell Smith over 9 years
    In this case there is no need to "make sure". "sign in" will literally be passed to the keyword, there's no question about that.
  • Wai Ha Lee
    Wai Ha Lee about 4 years
    That is what this answer said five years ago. Duplicate answers don't add value, shouldn't be posted, and are liable to be deleted. From Review.
  • ToonAlfrink
    ToonAlfrink about 4 years
    I came here with the question "what if I want to parse multiple spaces?" and this answer helped me most.