【发布时间】:2019-01-07 09:04:42
【问题描述】:
我需要用机器人框架删除这个“$,.”字符串,然后转换为数字。
例如这个字符串“$7,999.00”
我的代码:
${price}= Get Text xpath="...."
${proice} Replace String , . $
log to console ${price}
【问题讨论】:
标签: python selenium robotframework
我需要用机器人框架删除这个“$,.”字符串,然后转换为数字。
例如这个字符串“$7,999.00”
我的代码:
${price}= Get Text xpath="...."
${proice} Replace String , . $
log to console ${price}
【问题讨论】:
标签: python selenium robotframework
这可以通过 String 库中的 Remove String 关键字来完成。它支持可变数量的参数,所以是的,您可以传递所有需要删除的字符。
但不要删除点 (.) - 如果你这样做,你实际上会将值乘以 100:
${price}= Remove String ${price} , $
${price}= Convert To Number ${price}
# just to check is it really a number now - if the source string value was 10000.00:
${result}= Evaluate ${price} * 2
# , this should print 20000.00:
Log To Console ${result}
【讨论】:
${my var}= Remove string ${my var} "
*** Settings ***
Library String
*** Test Cases ***
Test 1
${price}= Get Price String As Integer $7,999.00
Log To Console \n ${price}
***Keywords***
Get Price String As Integer
[Arguments] ${string}
# ignore decimal values of price string
${price}= Fetch From Left ${string} .
# Remove $ , . from price string
${price}= Remove String ${price} $ ,
# Converting value to integer
${value}= Convert To Integer ${price}
[Return] ${value}
输出:7999
【讨论】:
我正在解决这种形式的问题:
#Get text of xpath
${price} Get Text xpath="..."
#Remove , and "
${price} Remove String ${price} , $
#conver to number
${price} Convert To Number ${price}
任何形式的感谢您的帮助!
【讨论】: