首页 > 解决方案 > 机器人框架显示:JavascriptException:消息:javascript 错误:无法使用“[ng-app]”找到根选择器

问题描述

我正在使用机器人框架并使用 SeleniumLibrary 和 AngularJSLibrary。

我有一个没有角度的登录页面,但后续页面有角度。当我运行使用机器人框架构建的端到端测试时,它会启动登录页面,但它什么也没做并且失败了。

错误信息:

JavascriptException: Message: javascript error: Unable to find root selector using "[ng-app]".
Please refer to the AngularJS library documentation for more information on how to resolve this error.

*** Settings ***
Documentation  "Angular demo".
...             Demo.

Library         SeleniumLibrary
Library         AngularJSLibrary

*** Keywords ***
Click clients and all accounts
    Wait for Angular
    Click Element   binding=::item.title | translate
    Click Element   xpath=//*[@id="clientsMenu"]/li[1]/button

Account page is displayed
    Title Should be     All-Accounts

Search an account
        Input Text      model=vm.searchDetails.searchString     123

标签: angularjsseleniumrobotframework

解决方案


我也有这个问题。我通过 grepping 在我的 Angular src 目录中找到了我的根选择器。

[devel@localhost src]$ grep selector . -r
./app/app.component.ts:  selector: 'app-root',

将参数添加到您的 .robot 库包括 AngularJSLibrary:

Library     AngularJSLibrary    root_selector=app-root 

注意“AngularJSLibrary”之后的多个空格。我希望这有帮助。


推荐阅读