Robot Framework Get Text

有些话、适合烂在心里 提交于 2019-12-11 14:55:37

问题


I am using Robot Framework Selenium using python. I need help with grabbing a certain part of the string, without getting an exterior library. lets say the text says " Your range price for your product is from $0- 400" So i want to be able to get the 400 and paste is somewhere else in the test. The number isnt always 400 sometimes it may be 55 or something different. So i think i would need a GET TEXT Starting from the dollar sign count two spaces and take whatever is left. or i can get the first number and add 10. Like in this example its 0 so i want it to paste 10. Please Let me Know!


回答1:


"Fetch From Right" should cover that. You just have to identify the stop point, which in your example looks like it would be the hyphen between the two number values.

for example: to extract the last five digits of this string ABC12345 you would want to create a variable to assign the text to.

${number}=    Get Text    (defined location of text, minus parentheses)

Then use this command to retrieve the remainder of the string after your identified stop point (C).

${desiredNumber}=    Fetch From Right    ${number}    C

This is essentially creating a new variable, which is defined as the extracted values from the original variable after that point.

Hopefully this helps.




回答2:


You could use the built-in function Evaluate to use the python underlying system:

${my_string}  Get Text  <your-identifier-here>
${result}  Evaluate  ${my_string}[${my_string}.rfind('-') + 1:]

Also, please have a look if you can use one of the standard available libraries: http://robotframework.org/robotframework/



来源:https://stackoverflow.com/questions/26299320/robot-framework-get-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!