【发布时间】:2017-07-10 08:41:46
【问题描述】:
我对关键字“Run Keyword If”也有疑问。 我研究了几乎所有来自 stackoverflow 的文章,并尝试了很多次不同的解决方案,不幸的是没有任何改进。 我发布那篇文章是希望有人能给我正确的提示。
问题如下:
我尝试做一个检查器来检查一个字段是否存在,该字段在后面
<input type="text" class="select-dropdown" readonly="true" data-activates="select-options-aaf80655-9ef4-37cc-6026-2f5989e82df1" value="Please select organisation">
如果该字段存在,则执行关键字“Select-ORG”,否则跳过。
所以我试图操作的代码如下所示(UPD:11.07):
<li class="step active" data-order="1">
<div class="step-title waves-effect"><b>General info</b></div>
<div class="step-content" style="left: 0%; display: block;">
<div class="row">
<div class="input-field col s12">
<div class="btn-types">
<div class="btn-group">
<button type="button" data-activity-type="1" class="btn btn-primary btn-activity-type selected"><span>Event</span></button>
<button type="button" data-activity-type="2" class="btn btn-primary btn-activity-type "><span>Repeating</span></button>
<input type="hidden" id="activity_type" name="activity_type" value="1">
</div>
</div>
</div>
<div class="clearfix"></div>
<br>
<div class="input-field col s12 ">
<div class="select-wrapper"><span class="caret">▼</span>
<input type="text" class="select-dropdown" readonly="true" data-activates="select-options-e1b60306-a7d2-ef9c-ecc9-3df0dec2ac24" value="Please select organisation">
<ul id="select-options-e1b60306-a7d2-ef9c-ecc9-3df0dec2ac24" class="dropdown-content select-dropdown" style="width: 1181px; position: absolute; top: 0px; left: 0px; opacity: 1; display: none;">
<li class=""><span>Please select organisation</span></li>
<li class=""><span>ORG-WITH-IMAGE</span></li>
<li class=""><span>ORG-WITHOUT-IMAGE</span></li>
</ul>
<select id="organisation_id" name="organisation_id" class="initialized">
<option value="0">Please select organisation</option>
<option value="782">ORG-WITH-IMAGE</option>
<option value="783">ORG-WITHOUT-IMAGE</option>
</select>
</div>
<label for="organisation_id">Organisation</label>
</div>
<div class="clearfix"></div>
</li>
机器人框架代码如下:
*** Settings ***
Resource Settings.robot
Resource Variables.robot
Library OperatingSystem
*** Test Cases ***
Check create Event
Open SiteURL
Login as Provider
Events - Add new
*** Keywords ***
Events - Add new
Sleep 1
Go To ${UrlSite}/cms/activity?t=1
Sleep 1
Click Element xpath=(//a[@class="add-btn-new"])[1]
Sleep 1
Log To Console Checke-one
Sleep 1
Log To Console Check-two
${CycleValue} = Run Keyword And Return Status Element Should Be Visible //input[@class="select-dropdown"][1]
Log To Console Check-three
Sleep 1
Log To Console Check-four
Run keyword If ${CycleValue} == "PASS" Select-ORG
Log To Console Check-five
Select-ORG
Sleep 1
Click Element xpath=(//input[@class="select-dropdown"])[1]
Sleep 1
Click Element xpath=//div[@class="row"]/div/div/ul/li[last()]/span
Sleep 1
The row that need to click is selected
可能是我的环境有问题:
- robotframework-3.0.2
- Python 2.7.11
- OS X El Capitan 版本。 10.11.6
【问题讨论】:
-
看起来您可能有拼写错误。“Log To Console Checke-one”是 Checke 末尾的额外 e
-
这是一个单独创建的关键字,特别是当必填字段存在的情况下,然后“运行关键字If”将执行它。
-
@StefanE ,这不是问题,这是我设置的消息。没关系。
-
${CycleValue}变量是否包含值:PASS?您是否尝试过引用:"${CycleValue}" == "PASS",因为两者都是字符串。 -
@A.Kootstra,从文档中,robotframework.org/robotframework/latest/libraries/…,结果我应该指出积极的状态,比如“PASS”。所以我做到了,但我没有看到点击必填字段完成。
标签: python selenium selenium-webdriver robotframework