got error if the xpath return nothing
See original GitHub issueHi
I noticed that currently jsnapy raise an error if the Xpath return nothing. It’s an issue for Xpath that are tracking error messages for example. We want to check for error but it the XPAth return nothing, it mean there is no error.
In the SLAX version, this Xpath was valid, it was just returning a list of 0 member
Maybe we should allow a Xpath to return an empty list and add an option to define the minimum numbers of elements an XPATH should return. I can see many cases where it would be handy. · Check there are 2 RE · Check there are 4 Uplinks etc …
Tests Included: check_alarm
************************ Command: show chassis alarms ************************
ERROR!! Nodes are not present in given Xpath: <//alarm-detail>
FAIL | "alarm-class" is in list ['Major', 'Warning'] [ 0 matched / 1 failed ]
Thanks Damien
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
XPath not returning anything when asked for table tag
I'm trying to extract table values from https://raw.githubusercontent.com/denisemauldin/immer/master/index.html but it returns nothing. Am I ...
Read more >Xpath3 returns empty string when values are not located
When xpath3 fails to identify an expected value, it will return an empty string. This article provides options to investigate this product behaviour....
Read more >Introduction to using XPath in JavaScript - MDN Web Docs
The XPathResult object returned is a node-set of matched nodes which will behave as an iterator, allowing us to access the individual nodes ......
Read more >Solved: Xpath returns null value - Power Platform Community
Solved: Hi, I'm getting null value when I tried to get sessionID using below function. Please help me on this.
Read more >Xpath error with empty variable and contains when it ...
I just tested this, and I believe this is a bug in Mendix, where the query is not being formed properly. A solution...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@maxdevyatov @dgarros The rational behind the current behaviour: Let’s say I run the following test:
Now there are two xpaths to consider here:
This is how the program works now:
The program treats the absence of nodes for a given xpath as error because:
What I propose:
Keeping in mind that there is demand for old behaviour, two solutions have been drawn up
In this, if the nodes along the xpath :
./chassis/chassis-module/chassis-sub-module/version
are absent then theno-exists
test would evaluate to true and skip the next operator. This way the whole test evaluates to True. If nodes are present, it works normally.I think we all are expecting too much from each operator. It would be better to intuitively divide the work between different operators and eliminate hidden behaviors. This way it becomes easier and less frustrating for new users to pick up the tool.
Request you to kindly comment.
I really liked the idea of introducing the ignore-null attribute.
Both options are good from the test file readability perspective.
I think the discussion is more about if we introduce the new attribute (which require additional changes) or leave as it is (to be solved with the conditional test operators, hence no additional coding is required).
An important thing to note is (assuming we only go with the conditional test operators):
Without de-valuing the conditional test operators, if I have to choose one of the options, I would go with the test attribute because this avoids me of using a conditional test operator, i.e., the test file is kept simple.
Thanks