简体   繁体   English

如何在Robot Framework关键字中用空格指定“参数”?

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

I am trying to automate the "gmail" login process.我正在尝试自动化“gmail”登录过程。

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. “单击登录按钮”关键字会引发“无效的定位器或 ID:登录”错误。 Taken this "sign in" from Inspect Element in "chrome" browser.从“chrome”浏览器中的“检查元素”中获取此“登录”。

*** 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?"您的问题“如何在 Robot Framework 关键字中指定带有空格的“参数”的字面答案 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" .该元素的 id 为"signIn" ,值为"Sign in" ,但没有匹配"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.注意:通常最好使用 ids 作为定位器,当它们可用时。 In your case it would be:在您的情况下,它将是:

Click Button    id=signIn

by using ${SPACE} keyword to we can resolve the issue.通过使用 ${SPACE} 关键字我们可以解决这个问题。 If you use the ${SPACE} keyword, Robot will understand it so that you would have one keyword ${msg}= HELLO${SPACE*5}WORLD Log ${msg}如果你使用 ${SPACE} 关键字,Robot 会理解它,这样你就会有一个关键字 ${msg}= HELLO${SPACE*5}WORLD Log ${msg}

Output: HELLO WORLD输出:你好世界

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Robot Framework删除字符串中的空格? - How to remove white space in a string with Robot Framework? 机器人框架中的 IF ELSE [关键字作为条件] - IF ELSE in robot framework [Keyword as a condition] 如何使用机器人框架关键字验证影子根中的文本节点 - How to verify text node in shadow root with robot framework keyword 如何在 Selenium Robot 框架中使用具有多个条件的“Exit For Loop IF”关键字 - How to use 'Exit For Loop IF' keyword with multiple condition in Selenium Robot framework 如何在机器人框架中使用执行 Javascript 关键字来单击元素 - How to use Execute Javascript keyword in robot framework for clicking an element 如何在 Robot 框架中传递命令行参数(测试数据参数) - How to pass command line arguments (test data parameters) in Robot framework 在 Robot Framework 中找不到 IN 关键字。 如何在不使用 IN 关键字的情况下使用 for 循环? - Unable to find IN keyword in Robot Framework. How to use for loop without using IN keyword? 在机器人框架中以毫秒为单位获取时间的关键字是什么? - What is the keyword to get time in milliseconds in robot framework? 用于连接和断开互联网的机器人框架关键字 - Robot Framework Keyword for Connecting and disconnecting internet 机械手框架中自定义关键字的整数变量 - Integer variable from a custom keyword in the robot framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM