机器人框架获取文本 [英] Robot Framework Get Text

查看:57
本文介绍了机器人框架获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Python 使用 Robot Framework Selenium.我需要帮助抓取字符串的某个部分,而不需要外部库.假设文字显示您的产品价格范围为 0-400 美元"所以我希望能够获得 400 并且粘贴在测试中的其他地方.数字并不总是 400,有时可能是 55 或不同的东西.所以我想我需要一个 GET TEXT 从美元符号开始计算两个空格并取剩下的任何东西.或者我可以得到第一个数字并加 10.就像在这个例子中它是 0,所以我希望它粘贴 10.请让我知道!

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!

推荐答案

从右侧获取"应该涵盖这一点.您只需要确定停止点,在您的示例中,它看起来像是两个数值之间的连字符.

"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.

例如:要提取此字符串 ABC12345 的最后五位数字,您需要创建一个变量来分配文本.

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)

然后使用此命令在您识别的停止点 (C) 之后检索字符串的其余部分.

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.

希望这会有所帮助.

这篇关于机器人框架获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆