2017-09-28 124 views
2

的情况下鼠标后会出现一个下拉列表中选择值:机器人框架 - 从超过

  1. 用户将移动鼠标在链接:ID_CHECK:R17AA003
  2. 的下拉列表中会自动出现
  3. 用户将点击从列表中选择一个测试类型

enter image description here

我想这个代码来实现这一目标:

Mouse over ${xpathToIdCheck} 
Page Should Contain Element xpath=//*[@id="list_of_test_types"] 5s 
Click Element ${User_Menu Link} 
Select From List xpath=//*[@id="list_of_test_types"] STR 

当我运行测试,机器人框架在id_Check链接移动鼠标,我们可以看到,该文本框出现:

enter image description here

但之后测试失败。显然它可以在网页上找到元素,但无法找到要点击的下拉框。

enter image description here

此我通过删除点击链接命令,并直接尝试后去了从列表中选择命令:

Mouse over ${xpathToIdCheck} 
Page Should Contain Element xpath=//*[@id="list_of_test_types"] 5s 
Select From List xpath=//*[@id="list_of_test_types"] STR 

但再次失败。反馈如下:

enter image description here

的HTML代码如下:

<form action="/change_test_type_id_check?page=1&amp;study_id=ID&amp;test_uuid=UUID" method="post" style="display:inline"> 
    <select class="list_of_test_types" id="list_of_test_types" name="`" onchange="this.form.submit()"> 
<option value="">Select a test type</option> 
<option value="STR">STR</option></select> 
    </form> 

另外,如果我的代码更改为

Select From List by Value xpath=//*[@id="list_of_test_types"] STR 

这也失败,与消息“ NoSuchElementException:消息:无法找到值为STR的选项:“

期待您的亲切支持。谢谢

+0

您是否找到任何解决方案? 我建议你使用autoIt – Emna

回答

3

您可以尝试如下。

`Mouse over ${xpathToIdCheck} 
Page Should Contain Element xpath=//*[@id="list_of_test_types"] 5s 
Click Element ${User_Menu Link} 
Mouse Down xpath=//li[contains(.,'${STR}')] 
Click Element xpath=//li[contains(.,'${STR}')]` 
+0

https://stackoverflow.com/questions/46682932/how-can-i-get-all-elements-of-autocomplete-list-with-robotframework 你能否看到这个问题,一个类似的问题,但在桌面应用自动化。 – Emna

+0

谢谢。我只需要将xpath修改为xpath = // option [contains(。,'STR')] – nhrcpt