简体   繁体   中英

InvalidSelectorError: The result of the xpath expression 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.

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"]/*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM