My Variable : 54, 22
我的变量:54,22
What I want : 54,22
我想要的是:54,22
I've tried :
我试过了 :
Execute Javascript var a = 54, 22;var x = a.split(' ').join('');return x
执行Javascript var a = 54,22; var x = a.split('')。join(''); return x
and
Execute Javascript var a = 54, 22;var x = a.replace(/\s/g, '');return x
执行Javascript var a = 54,22; var x = a.replace(/ \ s / g,'');返回x
and
log ${str.strip()}
But none of them solved my problem. When I execute these code seperately I got that error:
但他们都没有解决我的问题。当我单独执行这些代码时,我得到了这个错误:
FAIL : WebDriverException: Message: u'unknown error: Runtime.evaluate threw exception: SyntaxError: Unexpected number\n at Object.InjectedScript._evaluateOn (:895:140)\n at Object.InjectedScript._evaluateAndWrap (:828:34)\n at Object.InjectedScript.evaluate (:694:21)\n (Session info: chrome=43.0.2357.124)\n (Driver info: chromedriver=2.12.301325 (962dea43ddd90e7e4224a03fa3c36a421281abb7),platform=Windows NT 6.1 SP1 x86_64)'
FAIL:WebDriverException:消息:u'unknown错误:Runtime.evaluate引发异常:SyntaxError:在Object.InjectedScript._evaluateAndWrap(:828:34)处的Object.InjectedScript._evaluateOn(:895:140)\ n处的意外数字\ n \ n在Object.InjectedScript.evaluate(:694:21)\ n(会话信息:chrome = 43.0.2357.124)\ n(驱动程序信息:chromedriver = 2.12.301325(962dea43ddd90e7e4224a03fa3c36a421281abb7),platform = Windows NT 6.1 SP1 x86_64)'
How to solve that problem?
如何解决这个问题?
2 个解决方案
#1
0
You're missing commas in your variable, that's why you're getting syntax error:
你在变量中缺少逗号,这就是你得到语法错误的原因:
var a = '54, 22';
#2
2
Using the String Library
The String library has a Replace String keyword that you can use to remove whitespace, without having to resort to running javascript:
String库有一个Replace String关键字,可用于删除空格,而不必诉诸于运行javascript:
*** Settings ***
| Library | String
*** Test Cases ***
| Example of removing whitespace
| | ${value}= | Replace String | 54, 22 | ${space} | ${empty}
| | Should be equal | ${value} | 54,22
Using the Evaluate keyword
You can run arbitrary python code with the Evaluate keyword. For example:
您可以使用Evaluate关键字运行任意python代码。例如:
*** Test Cases ***
| Example of removing whitespace
| | ${value}= | Evaluate | "54, 22".replace(" ", "")
| | Should be equal | ${value} | 54,22
#1
0
You're missing commas in your variable, that's why you're getting syntax error:
你在变量中缺少逗号,这就是你得到语法错误的原因:
var a = '54, 22';
#2
2
Using the String Library
The String library has a Replace String keyword that you can use to remove whitespace, without having to resort to running javascript:
String库有一个Replace String关键字,可用于删除空格,而不必诉诸于运行javascript:
*** Settings ***
| Library | String
*** Test Cases ***
| Example of removing whitespace
| | ${value}= | Replace String | 54, 22 | ${space} | ${empty}
| | Should be equal | ${value} | 54,22
Using the Evaluate keyword
You can run arbitrary python code with the Evaluate keyword. For example:
您可以使用Evaluate关键字运行任意python代码。例如:
*** Test Cases ***
| Example of removing whitespace
| | ${value}= | Evaluate | "54, 22".replace(" ", "")
| | Should be equal | ${value} | 54,22