首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError: startswith

AttributeError: startswith
EN

Stack Overflow用户
提问于 2019-12-05 15:02:26
回答 1查看 291关注 0票数 1

我要用机器人框架运行一些测试,在某些元素可见之后,我想做一些事情:

这就是我试过的:

代码语言:javascript
复制
 Page Should Contain Element  ${TRAIN_LABEL}

 element should be visible  ${TRAIN_LABEL} 

 Wait Until Keyword Succeeds  ${RETRY_TIMEOUT}  ${RETRY_INTERVAL}  Wait Until Element is Visible  ${TRAIN_LABEL}

我的TRAIN_LABEL变量:

${TRAIN_LABEL} =xpath=//*@id=‘trainHeader’,并包含(@data-TRAIN_LABEL-id,'548')

但是当我运行测试时,它给了我:

AttributeError: startswith

错误。

我怎么才能解决这个问题?

html:

代码语言:javascript
复制
<div class="fleetTrainCell" data-train-id="548">
                <div id="trainHeader" class="fleetTrainInfoRow fleetTrainHeader" onclick="showTrainDetails(this.getAttribute('data-train-id'))" data-train-id="548">

                    <span id="name" class="fleetTrainName">UK390002</span>  

    </div>
                <div class="fleetTrainInfoRow fleetTrainTopRow">
                    <div class="empty fleetTrainCellIcon" title=""></div>
                    <div class="fleetTrainCellIcon empty"></div>
                    <div class="fleetTrainCellIcon empty"></div>                 
                    <div class="fleetTrainCellIcon">
                    <a href="#" onclick="showTrainDetails(this.getAttribute('data-train-id'));onAddMaintenanceEventsClicked();" data-train-id="548">                       
                            <img id="addMaintEventIcon" title="Add Maintenance Events" src="/App_Themes/Alstom/Icons/datebox-icon-enabled.png" style="border-width:0px;">                       
                    </a>
                    </div>
                </div>

                <div id="trainImageCell" title="Critical" class="fleetTrainImageCell redBackground" onclick="showTrainView(this.getAttribute('data-train-id'))" data-train-id="548" alarms="redBackground">

                    <img id="image" class="fleetTrainImage" src="../../../App_Themes/Alstom/Icons/Trains/train-Red.png" style="border-width:0px;">

</div>
            <div class="fleetTrainInfoRow fleetTrainBottomRow">            
                <div class="fleetTrainCellIcon">        
                    <a href="#" onclick="showTrainDetails(this.getAttribute('data-train-id'));showTrainSummary(this.getAttribute('data-train-id'), 'UK390002');" data-train-id="548">                
                        <img id="noInfoIcon" title="Summary" src="/App_Themes/Alstom/Icons/trains/info.png" style="border-width:0px;">  
                    </a>                      
                </div>                                  
                <div class="fleetTrainCellIcon">
                    <a id="link" class="clickableNotes" href="#" onclick="showNotes(548, 1);return(false);"><img id="img" title="Planning Note: a" class="notesExist" src="../../../App_Themes/Alstom/Icons/planning-note-new-icon.png" alt="Planning Note: a" style="border-width:0px;"></a> 
                </div>
                <div class="fleetTrainCellIcon">
                    <a id="link" class="clickableNotes" href="#" onclick="showEngineeringNotes(548);return(false);"><img id="img" title="Engineering Notes: 700" class="notesExist" src="../../../App_Themes/Alstom/Icons/engineering-note-icon-new.png" alt="Engineering Notes: 700" style="border-width:0px;"></a> 
                </div>
                <div class="maintenanceRequiredIcon  fleetTrainCellIcon" title="Anomalies Detected" onclick="showEngineeringNotes(this.getAttribute('data-train-id'), 2);" data-train-id="548">
                    <span class="trainAnomalyCount">9+</span>
                </div>
            </div>
        </div>

更详细的测试:

代码语言:javascript
复制
*** Variables ***
&{ENGINEER_ADMIN_USER_3}          username=leonel        password=Lenel@19        email=leonel@criticalsoftware.com           language=pt-TP     language_t=pt_PT      role=system-engineer
# train
&{Train_1}      train_id=UK390001
&{Train_2}      train_id=UK390002


*** Test Cases ***
    Should be able to see train color red on UK390002
        [Tags]    DEBUG
        [Template]  Should be able to see train color red on UK390002
        ${FLEET_PAGE_URL}   ${ENGINEER_ADMIN_USER_3}    ${Train_2}



*** Keywords ***

Should be able to see train color red on UK390002
  [Arguments]  ${FLEET_PAGE_URL}  ${user}  ${train}

  Go to Login Page    ${FLEET_PAGE_URL}
  Login With Correct Credentials  ${FLEET_PAGE_URL}  ${user}
  Locate train by id  ${train}  grid
  Logout

Locate train by id
  [Arguments]  ${train}  ${type}
  Locate train  ${train}
  Validate train  ${train}  ${type}

Locate train
    [Arguments]  ${train}
    Wait Until Page Does Not Contain  ${LOADING}
    sleep  2s
    Page Should Contain Element  ${TRAIN_LABEL}
    Element Should Be Visible  ${TRAIN_LABEL}
    Wait Until Keyword Succeeds  ${RETRY_TIMEOUT}  ${RETRY_INTERVAL}  Wait Until Element is Visible  ${TRAIN_LABEL}
    ${Train_ID}=  Get Text  ${TRAIN_LABEL}
    log to console  train id: ${Train_ID}
    should be equal  ${train.train_id}  ${Train_ID}
    Wait Until Keyword Succeeds  ${RETRY_TIMEOUT}  ${RETRY_INTERVAL}  Get Element Attribute  ${TRAIN_IMAGE}  src
    ${Train_Color}=  Get Element Attribute  ${TRAIN_IMAGE}  src
    should be equal  ${Train_Color}  ${TRAIN_IMAGE_COLOR}
    Wait Until Page Does Not Contain  ${LOADING}

测试存在/停止于:

代码语言:javascript
复制
Page Should Contain Element  ${TRAIN_LABEL}

代码语言:javascript
复制
Element Should Be Visible  ${TRAIN_LABEL}

代码语言:javascript
复制
Wait Until Keyword Succeeds  ${RETRY_TIMEOUT}  ${RETRY_INTERVAL}  Wait Until Element is Visible  ${TRAIN_LABEL}

这三个关键词都不起作用

EN

回答 1

Stack Overflow用户

发布于 2019-12-06 18:13:23

信息有限,但我会尝试:

您定义了${TRAIN_LABEL} = xpath=//*[@id='trainHeader'and contains(@data-train-id,'548')]

如果以上是变量部分,则在=后面的可选${TRAIN_LABEL}符号之后至少应该有2个空格。如果它不在变量部分中,则不能这样赋值。您需要使用Set Variable关键字:

代码语言:javascript
复制
${TRAIN_LABEL}    Set Variable    xpath=//*[@id='trainHeader'and contains(@data-train-id,'548')]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59197923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档