javascript 在量角器 angularjs 上指定了无效或非法的选择器错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29603804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
an invalid or illegal selector was specified error on protractor angularjs
提问by Eka Rudianto
so I've been using protractor as my e2e test angularjs component, and I've been facing this issue..
所以我一直在使用量角器作为我的 e2e 测试 angularjs 组件,我一直面临这个问题..
so I've got an html markup like this
所以我有一个这样的 html 标记
<div class="item">
<div class="item-grid">grid A</div>
<div class="item-actions">
<input type="image" class="item-action-image" title="info" src="images/icons/system-info.png">
<input type="image" class="item-action-image" title="event" src="images/icons/system-event.png">
</div>
</div>
<div class="item">
<div class="item-grid">grid B</div>
<div class="item-actions">
<input type="image" class="item-action-image" title="info" src="images/icons/system-info.png">
<input type="image" class="item-action-image" title="event" src="images/icons/system-event.png">
</div>
</div>
let's say if one of the input typed image above was clicked, there will be an information modal coming up to display the information.
假设如果单击上面输入的输入图像之一,则会出现一个信息模式来显示信息。
so I want to create a scenario on protractor to simulate those..
所以我想在量角器上创建一个场景来模拟那些..
the scenario would be
情况是
it("should've display grid information datas", function() {
element(by.css(".item:eq(0) > .item-actions > input[title='info']")).click();
browser.waitForAngular();
});
logical explanation for the above code is the protractor would select the first '.item'
element then click the 'input[title="info"]'
inside it right ?
上面代码的逻辑解释是量角器会选择第一个'.item'
元素然后单击'input[title="info"]'
里面的元素对吗?
but instead I got this error
但是我收到了这个错误
InvalidSelectorError: The given selector .item:eq(0) > .item-actions > input[title='info'] is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: An invalid or illegal selector was specified
therefore I've been stuck since I'm new to using protractor.. is there anybody that could help me solve this issue ?
因此,自从我刚开始使用量角器以来,我一直被困住了……有没有人可以帮助我解决这个问题?
回答by Andres D
You can chain ElementFinders. For example:
您可以链接 ElementFinder。例如:
$$('.item')
.get(1)
.$('input[title=info]')
.click();
Or
或者
element.all(by.css('.item'))
.get(1)
.element(by.css('input[title=info]')
.click();
Notice that $$('.abc')
is the same as element.all(by.css('.abc'))
and $('.abc')
is the same as element(by.css('.abc'))
请注意,$$('.abc')
与element.all(by.css('.abc'))
和$('.abc')
相同element(by.css('.abc'))