所以我一直在使用 Protractor 作为我的 e2e 测试 angularjs 组件,我一直面临这个问题..
所以我有这样的 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>
假设如果点击上面输入的其中一个输入图像,将会出现一个信息模式来显示信息。
所以我想在 Protractor 上创建一个场景来模拟那些......
场景是
it("should've display grid information datas", function() {
element(by.css(".item:eq(0) > .item-actions > input[title='info']")).click();
browser.waitForAngular();
});
上述代码的逻辑解释是 Protractor 将选择第一个 '.item'
元素,然后单击其中的 'input[title="info"]'
对吧?
但是我得到了这个错误
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
因此,自从我刚开始使用 Protractor 以来,我一直被困住了。有没有人可以帮助我解决这个问题?
最佳答案
您可以链接 ElementFinder。例如:
$$('.item')
.get(1)
.$('input[title=info]')
.click();
或者
element.all(by.css('.item'))
.get(1)
.element(by.css('input[title=info]')
.click();
请注意 $$('.abc')
与 element.all(by.css('.abc'))
和 $ 相同('.abc')
等同于 element(by.css('.abc'))
关于javascript - 在 Protractor angularjs 上指定了无效或非法的选择器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29603804/