【问题标题】:Protractor/PhantomJS gives DOM Exception 12 when trying to select a labelProtractor/PhantomJS 在尝试选择标签时给出 DOM 异常 12
【发布时间】:2017-01-13 12:18:34
【问题描述】:

我正在使用 Protractor 和 PhantomJS 来测试 Angular2 项目。使用 Chrome 运行时,我的测试通过了,但使用 PhantomJS 时,我在尝试使用 CSS 选择器选择标签的测试中遇到错误,如下所示:

element(by.css('label[for="my-id"'))

我得到的错误是:

Failed: {"errorMessage":"SyntaxError: DOM Exception 12","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"74","Content-Type":"application/json; charset=utf-8","Host":"localhost:15995","User-Agent":"Apache-HttpClient/4.5.1 (Java/1.8.0_101)"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"css selector\",\"value\":\"label[for=\\\"my-id\\\"\"}","url":"/elements","urlParsed":{"anchor":"","query":"","file":"elements","directory":"/","path":"/elements","relative":"/elements","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/elements","queryKey":{},"chunks":["elements"]},"urlOriginal":"/session/3e10b5e0-d873-11e6-830b-4d293c6fcef6/elements"}}

谷歌搜索“DOM Exception 12”,它 seems to be 与 ID 选择器的使用方式有关,但我相信我使用它的方式是正确的:

<label for="my-id">My Label</label>
<input id="my-id" type="text" ... />

有什么想法吗?

【问题讨论】:

    标签: angular phantomjs protractor


    【解决方案1】:

    CSS 选择器实际上是无效,缺少一个右方括号:

    element(by.css('label[for="my-id"]'));
                                 HERE^
    

    请注意,如果您在选择的 IDE 中使用 ESLinteslint-plugin-protractor plugin,您可以及早发现此类问题。例如。在 WebStorm 中,它会即时警告您:

    【讨论】:

    • 天才,绝对正确,绝对是我错过的东西,谢谢。
    猜你喜欢
    • 2013-03-20
    • 2015-07-10
    • 1970-01-01
    • 2013-04-10
    • 2011-11-30
    • 2018-12-01
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    相关资源
    最近更新 更多