首页 文章

机器人框架元素不可见的例外

提问于
浏览
2

我收到一个ElementNotVisibleException虽然我不知道为什么 . 当我查看日志中的屏幕截图时,该元素清晰可见 . 它是javascript控件的按钮,无论是启用还是禁用 . 这是残疾人状态:

<button id="continue" type="submit" class="btn btn-primary btn-lg next pull-right btn-group-vertical" data-bind="enable: selectedRegistrationCandidates().length > 0" disabled="">Continue</button>

这是启用状态:

<button id="continue" type="submit" class="btn btn-primary btn-lg next pull-right btn-group-vertical" data-bind="enable: selectedRegistrationCandidates().length > 0">Continue</button>

我确定在尝试点击之前元素已启用但是当我尝试这个时我得到一个ElementNotVisibleException:

Select Individual
   Click Element  ${lnkFirstPerson}
   Wait Until Page Does Not Contain   NOBODY SELECTED
   Wait Until Element Is Enabled    ${btnContinue}
   Click Element  ${btnContinue}
   Wait Until Page Contains    Return to Step 1

谁能解释为什么和可能的解决方案?

1 回答

  • 0

    这里有两种可能性 .

    1) Switch to Frame where submit button is present:

    “提交”按钮可能位于不同的框架中 . 如果是这种情况,首先切换到框架,然后单击十元素 .

    选择个人点击元素$

    Wait Until Page Does Not Contain   NOBODY SELECTED
    
       Select Frame  **Locator**   # i have added Select Frame Keyword here
    
       Wait Until Element Is Enabled    ${btnContinue}
    
       Click Element  ${btnContinue}
    
       Wait Until Page Contains    Return to Step 1
    

    有关详细信息,请参阅:https://github.com/robotframework/Selenium2Library/issues/201

    然而 . 因为这不是一种正常的做法,所以这种可能性较小 .

    2)使用JavaScript执行操作

    请尝试使用以下关键字 .

    选择个人

    Click Element  ${lnkFirstPerson}
    
       Wait Until Page Does Not Contain   NOBODY SELECTED
    
       Wait Until Element Is Enabled    ${btnContinue}
    
       Execute JavaScript  $("#continue").click();
    
       # i have left Commented Click Element below to show  you changes i have         
       # made more clearly.I have added Javascript above.
    
       #Click Element  ${btnContinue}
    
       Wait Until Page Contains    Return to Step 1
    

    虽然在编写脚本时不建议这样做,因为它不会检查提交按钮是否实际出现在UI上 . 但是你肯定可以在确定UI上存在元素的地方使用它 .

相关问题