2017-01-12 42 views
1

我正在使用量角器和PhantomJS來測試Angular2項目。當Chrome瀏覽器運行,我的測試中經過精磨,但PhantomJS我得到了測試的錯誤,試圖用一個CSS選擇器選擇一個標籤,像這樣:量角器/ PhantomJS在嘗試選擇標籤時給出DOM異常12

我得到的錯誤是:

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" ... /> 

有什麼想法?

回答

3

的CSS選擇器實際上是無效,有缺少一個右括號:

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

注意,您可以及早發現這類問題,如果你會在你選擇的IDE中使用ESLinteslint-plugin-protractor plugin 。例如。在WebStorm它會提醒你在即時:

enter image description here

+0

天才,絕對正確,絕對的東西我已經錯過了,謝謝你。 –

相關問題