简体   繁体   中英

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

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM