Robot Framework - 等到表单文本字段包含文本
Robot Framework - Wait until a form textfield contains text
对于我的测试,我需要等到表单文本字段填满文本并且我想检查该文本。这是一个根据邮政编码自动填写街道和城市的地址表。
使用 "Wait until element contains" 对我不起作用,我想避免使用睡眠然后使用 "textfield should contain",因为时间可变。
谢谢!
Wait Until Element Contains
对您不起作用,因为它 "waits" 元素的文本具有所需的值 - 即 in the documentation。
同时,Textfield Should Contain
作用于<input>
html元素,并检查它们的value
属性(这是存储用户设置的文本的内容)。因为它对你有用,你的目标元素是 <input>
一个,对吧?
为了得到value
,你应该使用关键字Get Element Attribute
来得到属性的值;等到它更新了,你可以把它包在 Wait Until Keyword Succeeds
里——这里是后者的 documentation.
粗略样本:
*** Test Cases ***
Check the value is correct
Wait Until Keyword Succeeds retry=10s retry_interval=200ms The value of the input should be expected text
# will check the value of the input every 200ms, and continue if it matches "expected text"
# if it does not matches in 10 seconds, the keyword and the case will be failed.
*** Keywords ***
The value of the input should be
[Arguments] ${expected}
${actual value}= Get Element Attribute locator_for_the_element value
Should Be Equal As Strings ${actual value} ${expected}
在@Todor 的帮助下,我最终使用了这个:
Wait Until Keyword Succeeds 1min 1s Textfield Should Contain Fieldname Value
您可以使用元素应包含关键字
Element Should Contain xpath=//div[@class="clr"] sampleText
对于我的测试,我需要等到表单文本字段填满文本并且我想检查该文本。这是一个根据邮政编码自动填写街道和城市的地址表。
使用 "Wait until element contains" 对我不起作用,我想避免使用睡眠然后使用 "textfield should contain",因为时间可变。
谢谢!
Wait Until Element Contains
对您不起作用,因为它 "waits" 元素的文本具有所需的值 - 即 in the documentation。
同时,Textfield Should Contain
作用于<input>
html元素,并检查它们的value
属性(这是存储用户设置的文本的内容)。因为它对你有用,你的目标元素是 <input>
一个,对吧?
为了得到value
,你应该使用关键字Get Element Attribute
来得到属性的值;等到它更新了,你可以把它包在 Wait Until Keyword Succeeds
里——这里是后者的 documentation.
粗略样本:
*** Test Cases ***
Check the value is correct
Wait Until Keyword Succeeds retry=10s retry_interval=200ms The value of the input should be expected text
# will check the value of the input every 200ms, and continue if it matches "expected text"
# if it does not matches in 10 seconds, the keyword and the case will be failed.
*** Keywords ***
The value of the input should be
[Arguments] ${expected}
${actual value}= Get Element Attribute locator_for_the_element value
Should Be Equal As Strings ${actual value} ${expected}
在@Todor 的帮助下,我最终使用了这个:
Wait Until Keyword Succeeds 1min 1s Textfield Should Contain Fieldname Value
您可以使用元素应包含关键字
Element Should Contain xpath=//div[@class="clr"] sampleText