在尝试选择标签时,Protractor / PhantomJS提供DOM Exception 12

时间:2017-01-12 15:58:00

标签: angular phantomjs protractor

我正在使用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例外12”,它seems to be与ID选择器的使用方式有关,但我相信我使用它的方式是正确的:

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

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

CSS选择器实际上无效,缺少结束方括号:

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

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

enter image description here