我想将值设置到某些输入标签中,但在类型为 number 的输入标签处总是失败。
输入形式是这样的:
<div class="f-col grow-2">
<div class="field">
<label class="label-small">Alert ID</label>
<input type="number" min="0" class="input-text " autocapitalize="off" autocomplete="off" name="alert_id" value="">
<span class="msg-helper"></span>
</div>
</div>
<div class="f-col grow-4">
<div class="field">
<label class="label-small">Title</label>
<input type="text" class="input-text " autocapitalize="off" autocomplete="off" name="alert_title" value="">
<span class="msg-helper"></span>
</div>
</div>
这是我用来输入号码的代码
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${FILTER_ID_LOC} = name=alert_id
${FILTER_TITLE_LOC} = name=alert_title
*** Keywords ***
user inputs on filter
[Arguments] ${title} ${alert_id}
Fill title ${title}
Fill id ${alert_id}
Fill title
[Arguments] ${value}
run keyword and continue on failure input text ${FILTER_TITLE_LOC} ${value}
Fill id
[Arguments] ${value}
run keyword and continue on failure input text ${FILTER_ID_LOC} ${value}
*** Test Cases ***
Scenario: User inputs values on filter
[Template] user inputs on filter
# title # alr_id
some_title 100
我使用了 chrome webdriver,但它不起作用。机器人框架显示错误消息:
InvalidElementStateException: Message: invalid element state: Element is not currently interactable and may not be manipulated
(Session info: chrome=64.0.3282.167)
(Driver info: chromedriver=2.31.488774
(7e15618d1bf16df8bf0ecf2914ed1964a387ba0b),platform=Mac OS X 10.11.6 x86_64)
还需要更多东西吗? 我只在
文档中找到了
input text
。
正确的做法是什么?
@Todor 是正确的。该错误很常见,研究 StackOverflow 将为您提供多种解释。
用更实际和更简单的术语来说,您所需的元素前面可能有另一个元素,或者您的元素尚未准备好接受输入,因为它需要通过用户事件激活。最有可能的是焦点或点击。
因此,通常建议就是这样做。
Click Element
在 Input Element
之前无缘无故地遇到此问题。
此处给出了示例机器人代码以实现您的目标:
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${FILTER_ID_LOC}= alert_id
${FILTER_TITLE_LOC} = alert_title
*** Keywords ***
*** Test Cases ***
Scenario: User inputs values on filter
Open Browser http://127.0.0.1:5500/index.html Chrome
Click Element xpath://*[@name="${FILTER_ID_LOC}"]
Input Text xpath://*[@name="${FILTER_ID_LOC}"] 100
Click Element xpath://*[@name="${FILTER_TITLE_LOC}"]
Input Text xpath://*[@name="${FILTER_TITLE_LOC}"] 100
Sleep 3
Close Browser