RobotFramework,如何检查页面上的文本 [英] RobotFramework, how to check text on page
问题描述
如果点击按钮后页面上出现文本.
if there appears text on a page after hitting a button.
它唯一的东西是一个类,就像这样:
the only thing it is in is a class, like so:
<label class="err">2 van de 3 velden Eiwit, Koolhydraten, Vet zijn leeg.</label>
你应该验证什么?
我试过了:
Page Should Contain Textfield err
但我认为这不是要走的路
but that's not the way to go I think
*** Keywords ***
Open Browser To Login Page
Open Browser ${LOGIN URL} ${BROWSER}
Maximize Browser Window
Set Browser Implicit Wait 5
Set Selenium Speed ${DELAY}
Login Page Should Be Open
Login Page Should Be Open
Title Should Be Hippe testautomatisering getest i.c.m. testtechnieken
Go To Login Page
Go To ${LOGIN URL}
Login Page Should Be Open
Input Username
[Arguments] ${username}
Input Text voedselnaam ${username}
Input Password
[Arguments] ${password}
Input Text Eenheid ${password}
Input Text Kcal ${password}
Input Text Eiwit ${password}
Submit Credentials
Click Element getdata
page should contain //label[@class='err'] 2 van de 3 velden Eiwit, Koolhydraten, Vet zijn leeg.
Welcome Page Should Be Open
Location Should Be ${LOGIN URL}
Title Should Be Welcome Page
推荐答案
有多种选择,选择最适合您的套件
There are various options choose which suites you most
使用关键字
如果你想要精确的文本匹配,那么使用
If you want exact text match then use
Element Text Should Be //label[@class='err'] 2 van de 3 velden Eiwit, Koolhydraten, Vet zijn leeg.
如果你想要文本中的子字符串
If you want substring in text
Element Should Contain //label[@class='err'] velden
它一直等到页面上出现带有文本的定位器,我认为另一个选项足以为您验证文本
It waits until the locator with text appears on page , I think another option to suffice to serve you verify text
Wait Until Element Contains locator text
这将验证整个页面上的文本,因此它可能在页面上出现多次或仅出现一次
This will verify text on entire page so it may be present multiple times on page or only single time
Wait Until Page Contains text_you_want_to_verify_on_page
使用定位器
匹配完整文本
//label[text()="2 van de 3 velden Eiwit, Koolhydraten, Vet zijn leeg."]
匹配部分文本
//label[contains(text(),'velden')]
并将其传递给验证页面元素的关键字之一.如需更多选项,您可以在这里探索
and pass it to one of keyword which verifies element on page. for more option you can explore here
这篇关于RobotFramework,如何检查页面上的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!