运行关键字如果 - 没有执行时返回OK结果

时间:2017-07-10 08:41:47

标签: python selenium selenium-webdriver robotframework

关键字“运行关键字”也存在问题。 我已经调查了几乎所有来自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

CMD display that all is OK

The row that need to click is selected

我的环境可能存在问题:

  • robotframework-3.0.2
  • Python 2.7.11
  • OS X El Capitan ver。 10.11.6

1 个答案:

答案 0 :(得分:1)

你几乎就在那里 - Run Keyword And Return Status没有返回字符串'PASS'/'FAIL'但它返回一个真正的布尔TrueFalse。因此,您的检查不会成功 - 它会进行字符串匹配比较 - 但这个简单的更改将会:

Run keyword If  ${CycleValue}     Select-ORG

如果${CycleValue}True,则Select-ORG将会运行,否则为 -