[英]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.