最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - InvalidSelectorError: The result of the xpath expression is [object Text]. It should be an element - Stack Overflow

programmeradmin1浏览0评论

I have the following code:

//html
<div>
   <span>Sort Order</span>
   <select id="sortOrderSelect">
      <option value=0>Descending</option>
      <option value=1>Ascending</option>
   </select>
</div>

//test
it('Check it has 2 options', function () {
   var selectCount = element.all(by.xpath('//*[@id="sortOrderSelect"]/child::node()'));
   expect(selectCount.count()).toBe(2);
});

I am getting the error below. Can someone explain to me what does the error means? And how can I solve it?

InvalidSelectorError: The result of the xpath expression "//*[@id="sortOrderSelect"]/child::node()" is [object Text]. It should be an element.

I have the following code:

//html
<div>
   <span>Sort Order</span>
   <select id="sortOrderSelect">
      <option value=0>Descending</option>
      <option value=1>Ascending</option>
   </select>
</div>

//test
it('Check it has 2 options', function () {
   var selectCount = element.all(by.xpath('//*[@id="sortOrderSelect"]/child::node()'));
   expect(selectCount.count()).toBe(2);
});

I am getting the error below. Can someone explain to me what does the error means? And how can I solve it?

InvalidSelectorError: The result of the xpath expression "//*[@id="sortOrderSelect"]/child::node()" is [object Text]. It should be an element.

Share Improve this question asked Sep 13, 2014 at 13:00 user2678324user2678324 1
  • 1 Browsers may insert empty text nodes when there are newlines between tags. – Pointy Commented Sep 13, 2014 at 13:02
Add a ment  | 

1 Answer 1

Reset to default 6

This XPath can return either text node or element :

//*[@id="sortOrderSelect"]/child::node()

But seems that the library you're using only support XPath expressions that return element :

//*[@id="sortOrderSelect"]/*

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论